#### Archived

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

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

## 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 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) )    followThread();

##### 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.

Parameters

stream

Pointer to FILE structure

format

Format-control string

argument

Optional arguments

Remarks

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.

+AA_970+

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

##### 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).

Morgan

##### 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

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 12
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632152
• Total Posts
3004466

×