#1
  1. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,350
    Rep Power
    61

    Weird character sequence at end of a few lines is messing up my c executables


    I'm taking over code from the previous programmer and am running into problems with one of his c executables. Specifically, this script opens up a file and reads it in one line at a time (using fgets), then processes it. However in a few instances, instead of reading in one line it's reading in multiples (which it's not supposed to do).

    When I open up the original text file in vi the offending lines have a ^@ sequence at the end. So for example there might be lines like

    Hello there ^@
    How are you doing ^@
    That's great.

    Although this is three lines, fgets is reading it as

    Hello there How are you doing That's great.

    Now the ^@ sequence is not a carat following by an @ sign. For example, the file is separated by form feeds (ascii value 12). When I look at it through vi, however, it shows up as ^L. This ^@ must represent a sequence similar to the form feed (again, it's not simply the same as typing ^@). So my questions are:

    1. What is the ^@ sequence? If I knew, I could do a search and replace.
    2. Is there any way that I can force c to treat it like a new line character?

    Thank you for any help that you can give.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    fgets reads until it encounters a new line. You will have to convert the form feeds to new lines.
    Last edited by Onslaught; January 29th, 2003 at 03:01 PM.
  4. #3
  5. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,350
    Rep Power
    61
    Actually, the situation is more like

    Hello there ^@
    How are you doing ^@
    That's great.
    ^L

    The ^L is the actual form feed character, which is used to separate a record. I have no idea what the ^@ is, so don't even know how to search for (and thus replace) it.

    However, I rewrote the previous programmer's script in Perl. Perl simply disgarded those ^@ characters, so I at least got my project done. However, it would be interesting to know what exactly tha ^@ sequence is. In any event, thanks for the help.
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    You can always look at the file in hex mode and see what that particular sequence is.

IMN logo majestic logo threadwatch logo seochat tools logo