fgets Error

This is a discussion on fgets Error within the C++ Programming forums, part of the General Programming Boards category; Code: void UpdateQuestions() { SendMessage(lbQuestions, LB_RESETCONTENT, 0, 0); strcpy(Path, RootDirectory); strcat(Path, Course); strcat(Path, "\"); strcat(Path, Unit); strcat(Path, "\Questions.txt"); Questions = ...

  1. #1
    Epo
    Epo is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    fgets Error

    Code:
    void UpdateQuestions()
    {
    	SendMessage(lbQuestions, LB_RESETCONTENT, 0, 0);
    	strcpy(Path, RootDirectory);
    	strcat(Path, Course);
    	strcat(Path, "\\");
    	strcat(Path, Unit);
    	strcat(Path, "\\Questions.txt");
    	Questions = fopen(Path, "r");
            while (fgets(FileLine, sizeof(FileLine), Questions) != NULL) /////////////////////////
    	{
    	   char *p = strchr(FileLine, '\n');
    	   if (p != NULL) *p = '\0';
    	   SendMessage(lbQuestions, LB_ADDSTRING, 0, (LPARAM)FileLine);
    	}
    	fclose(Questions);
    }
    I get an error on the line with all the "/"s, specifics are:

    ----------------------------------------------------------------
    | Debug Assertion Failed!
    |
    | Program: C:\Generator\Debug\Generator.exe
    | File: fgets.c
    | Line: 60
    |
    | Expression: str!= NULL
    |---------------------------------------------------------------

    But, I don't get it, cause this code has been working fine until now. I changed it around though, because I put it into a function, and made the "Path", "FileLine", and "Questions" variables global. Should I not do that? Any help appreciated

    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I changed it around though, because I put it into a function, and made the "Path", "FileLine", and "Questions" variables global. Should I not do that?
    In general, global variables make your program much harder to follow.

    Code:
    Questions = fopen(Path, "r");
    You never check the return value of fopen. We have to assume that it actually was able to open the file. You might (read:should always) want to check that.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21