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

Posted on 2006-05-19
Last Modified: 2010-08-05
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

Question by:Solaron
    LVL 53

    Accepted Solution

    Basically, you read in a line of the file, using fgets eg. :

    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 ?
    LVL 53

    Expert Comment

    typo :

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

    should be :

    >> If the last character in the string is a '\n'
    LVL 5

    Expert Comment

    If you have file that has a particular patter, you might consider using


    Check this tutorial.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    In desperate need of help 8 124
    Where is my core dump file in Ubuntu? 12 413
    Change to the struct 72 188
    Passing a array as parameter - C 2 70
    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now