Author Topic: Code Blocks won't read in files correctly  (Read 9970 times)

bassmasta79

  • Guest
Code Blocks won't read in files correctly
« on: September 12, 2012, 03:37:47 am »
Hello I am having trouble with Code Blocks reading in files on my laptop. I have been trying to get it to work and am using a simple program to print out a number from a file, and even at the lowest level, Code Blocks seems to have trouble. I think it is a problem with my laptop though, as the exact same code works on other computers.

int main(){
    FILE * ifp;
    int num, i;

    ifp = fopen("numbers.txt", "r");
    fscanf(ifp, "%d", &num);
    printf("%d", num);

return;
}

I am on windows using latest version of code blocks and the text file is in the same location as the C file.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Code Blocks won't read in files correctly
« Reply #1 on: September 12, 2012, 04:05:45 am »
Hello I am having trouble with Code Blocks reading in files on my laptop. I have been trying to get it to work and am using a simple program to print out a number from a file, and even at the lowest level, Code Blocks seems to have trouble. I think it is a problem with my laptop though, as the exact same code works on other computers.

int main(){
    FILE * ifp;
    int num, i;

    ifp = fopen("numbers.txt", "r");
    fscanf(ifp, "%d", &num);
    printf("%d", num);

return;
}

I am on windows using latest version of code blocks and the text file is in the same location as the C file.

Off topic. But, I suggest putting the text file in the same folder as the created exe file.

You might wish to read the FAQs; especially if this thread is deleted as being off-topic.
http://wiki.codeblocks.org/index.php?title=FAQ
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
http://wiki.codeblocks.org/index.php?title=FAQ-Issues_and_Workarounds#Q:_I_posted_on_the_forums_that_Code::Blocks_was_not_working.2C_but_no_one_could_help_me.3F
 

Tim S.
« Last Edit: September 12, 2012, 04:07:57 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org