News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Code Blocks won't read in files correctly

Started by bassmasta79, September 12, 2012, 03:37:47 AM

Previous topic - Next topic

bassmasta79

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.

stahta01

#1
Quote from: bassmasta79 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.

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]