Can anyone explain this stuff to me?
Hi,
here''s a few lines of code from a tutorial I''ve been doing. I''ve written comments next to the lines explaining what I have guessed that the line is doing. If someone could confirm, that would be great.
sprintf(filename, "%s/info", dir); // makes string filename equal to dir + /info ??? (replaces %s with third arg)
fgets(buffer, 255, fp); // get 255 chars from file ''fp'' and put into string ''buffer'' ???
while(!feof(fp) && count < mNumFrames) // feof = "found end of file"?
if (!mW) // does this mean is mW is equal to NULL or 0, or either?
I realise it''s pretty basic stuff. Is there a Java-esque API out there for the standard C++ libraries? I tried just reading their header files, but they all seem to be gobledey-gook.
quote:Original post by wombatvvv
sprintf(filename, "%s/info", dir); // makes string filename equal to dir + /info ??? (replaces %s with third arg)
Yes. printf() and its cousines takes an formatted string (like "%s/info"), and inserted the following vairables into it.
quote:
fgets(buffer, 255, fp); // get 255 chars from file 'fp' and put into string 'buffer' ???
Not exactly. fgets() reads a line from the file. 255 in that example is the size of the buffer, so it won't overwrite memory.
quote:
while(!feof(fp) && count < mNumFrames) // feof = "found end of file"?
feof() (File-EndOfFile) returns true when the file pointer is at the end of the file. The other part I cannot explain, as I don't know what they are used to, but in plain english, it whiles as long as there's anything left of the file and count is less than nNumFrames.
quote:
if (!mW) // does this mean is mW is equal to NULL or 0, or either?
The expression is true, if mW is not. TRUE is defined as anything non-zero, so the following statement or code block will execute if mW is FALSE, that is NULL or Zero.
[edited by - CWizard on August 31, 2002 9:19:28 PM]
sprintf(filename, "%s/info", dir);
appends "/info" to the directory name and stores it in filename.
fgets(buffer, 255, fp);
Get''s a string from the stream size of 255 (max)
while(!feof(fp) && count < mNumFrames)
Do while you haven''t reached the end of the file and the count doesn''t exceed the number of frames. If either condition is evaulated to not be true, then the loop breaks
appends "/info" to the directory name and stores it in filename.
fgets(buffer, 255, fp);
Get''s a string from the stream size of 255 (max)
while(!feof(fp) && count < mNumFrames)
Do while you haven''t reached the end of the file and the count doesn''t exceed the number of frames. If either condition is evaulated to not be true, then the loop breaks
wombatvvv:
I would suggest you look into C++''s stream classes. They are much easier to use, and you don''t have to deal with the old stdio functions.
John.
I would suggest you look into C++''s stream classes. They are much easier to use, and you don''t have to deal with the old stdio functions.
John.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement