• C

Fairly simple: How do i scan in a string until END OF LINE?

I am reading in a text file from a program called DL_POLY and i want to manipulate it with a small c program (these input files are HUGE otherwise i would have done it by hand)

The first line is the title, second line as 2 numbers that represent some other info.

So, very basic question:

How do i get it to automaitcally read in that title line and store it into ONE variable? i'm having froube getting the code to recognise that the end of the line is the end of the variable.

Any hints are appreciated

Chris
SolaronAsked:
Who is Participating?
 
Infinity08Commented:
Basically, you read in a line of the file, using fgets eg. :

http://www.cplusplus.com/ref/cstdio/fgets.html

If the last character in the string if a '\n' (which is the case if the buffer was large enough, and EOF was not met), then you replace it with a '\0'.

Is that what you wanted to know ?
0
 
Infinity08Commented:
typo :

>> If the last character in the string if a '\n'

should be :

>> If the last character in the string is a '\n'
0
 
cryptosidCommented:
If you have file that has a particular patter, you might consider using

fscanf()

http://www.crasseux.com/books/ctutorial/fscanf.html

Check this tutorial.

http://computer.howstuffworks.com/c19.htm


Regards,
siddhesh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.