• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

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
0
Solaron
Asked:
Solaron
  • 2
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now