Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can't read from a file in Windows...

Hey, I'm having a problem reading a stndard text file in my Win32 program. Before I go any further, let me post the source here.



if((infile = fopen("default.cfg", "rt")) == NULL)

{

probnum = 2;

}

else

{

fscanf(infile, "%d
", screenx_max);

fscanf(infile, "%d
", screeny_max);

fclose(infile);

}



Now, if I comment out the two fscanf() lines, it runs fine. If not, it gives me an error and crashes. I wrote to the file using fprintf, in the EXACT same format. I opened the file with notepad and the two lines are there. Line one is 800 and line two is 600. Why can't i read from this file without crashing?


Comments

  • Try

    fscanf(infile, "%d
    ", &screenx_max);

    fscanf(infile, "%d
    ", &screeny_max);



    Because scanf and its sisters expects a pointer



    : Hey, I'm having a problem reading a stndard text file in my Win32 program. Before I go any further, let me post the source here.

    :

    : if((infile = fopen("default.cfg", "rt")) == NULL)

    : {

    : probnum = 2;

    : }

    : else

    : {

    : fscanf(infile, "%d
    ", screenx_max);

    : fscanf(infile, "%d
    ", screeny_max);

    : fclose(infile);

    : }

    :

    : Now, if I comment out the two fscanf() lines, it runs fine. If not, it gives me an error and crashes. I wrote to the file using fprintf, in the EXACT same format. I opened the file with notepad and the two lines are there. Line one is 800 and line two is 600. Why can't i read from this file without crashing?

    :






  • THANKS A MILLION! I could NOT figure out why it wouldn't read that file. I'll have to pay closer attention to the code next time. Once again, thanks, I owe ya'!




Sign In or Register to comment.