Advertisement Jump to content


This topic is now archived and is closed to further replies.


Fread: How about reading in just an integer?

This topic is 6782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I understand how to read in one line: file.getline(scanline, 255); now how about if a line is like this: 32 and I want to put that into TexNum?

Share this post

Link to post
Share on other sites
The answer to this really depends on what exactly you''re trying to do and why. For instance, you may have wanted to write the number to the file in binary in the first case, in which case a spiel on converting from ASCII to binary won''t help you at all. Post what exactly you''re doing and why, and I''m sure somebody will be able to help you.

while( strcmp(reply,flame) )


Share this post

Link to post
Share on other sites
I'm not sure what your trying to do, but if your trying to read that number from a file and set a variable equal to it you can use fscanf. Here's the info from the VC++ docs:

int fscanf( FILE *stream, const char *format [, argument ]... );

Return Value

Each of these functions returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. If an error occurs, or if the end of the file stream is reached before the first conversion, the return value is EOF for fscanf or WEOF for fwscanf.



Pointer to FILE structure


Format-control string


Optional arguments


The fscanf function reads data from the current position of stream into the locations given by argument (if any). Each argument must be a pointer to a variable of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf; see scanf for a description of format. If copying takes place between strings that overlap, the behavior is undefined.


Edited by - +AA_970+ on June 23, 2000 11:53:33 PM

Share this post

Link to post
Share on other sites
Try this:

sscanf( scanline, "%d", &TexNum );

It just does scanf() on a string. Really easy (Do this after you read in the line of course).


Share this post

Link to post
Share on other sites
if it is in a textfile do this......
ifstream inFile(filename);
int x;
inFile >> x;

x is now equal to the number in the text file

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!