End of Line character

This is a discussion on End of Line character within the C Programming forums, part of the General Programming Boards category; I'm scanning in a line of words and need to stop at the end of a line from a data ...

  1. #1

    End of Line character

    I'm scanning in a line of words and need to stop at the end of a line from a data file.

    push this is the first line
    pop 4
    push this is the next line
    pop 21
    push good luck
    push this is the last assignment for the semester
    pop 15

    the first word is what to do with the next set of data. Push words onto a stack, pop a certain number from stack....
    HOw would I find the last word on a line?

  2. #2
    Code Warrior
    Join Date
    Nov 2001

    Read the whole line until the character '\n' is found.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Read the whole line from the file and then test (if-else statement) for a ' ' char. Understand?

    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Dec 2001
    Looking for the last word on the line:

    begin by searching for a space OR a newline, read everything.
    if a newline is hit, this is the last word.
    if a space is hit, set your index variable (usually i) to 0 and set the
    string you used for reading to '\0', like string[0] = '\0'
    continue reading the line

    the string you used should hold the last word of the line
    by using getchar, you can easily read from input and only store the last word

    else you'll have to use another index variable (j perhaps) and never set it to 0, unless the whole line is finished
    for reading from file you'll need fgetc (of course)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 03:40 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21