Thread: End of Line character

  1. #1
    jloyd01
    Guest

    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
    print
    push good luck
    push this is the last assignment for the semester
    pop 15
    print
    delete_stack

    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
    Posts
    669
    Hi!

    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
    Posts
    1,584
    Read the whole line from the file and then test (if-else statement) for a ' ' char. Understand?

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    9
    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
    repeat

    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, 09:13 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06: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, 02: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