The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Weird character sequence at end of a few lines is messing up my c executables
Discuss Weird character sequence at end of a few lines is messing up my c executables in the C Programming forum on Dev Shed. Weird character sequence at end of a few lines is messing up my c executables C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 29th, 2003, 02:35 PM
|
 |
300lb Bench!
|
|
Join Date: Aug 2001
Location: New York
|
|
|
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.
|

January 29th, 2003, 02:55 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
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.
|

January 29th, 2003, 07:15 PM
|
 |
300lb Bench!
|
|
Join Date: Aug 2001
Location: New York
|
|
|
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.
|

January 29th, 2003, 08:03 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
You can always look at the file in hex mode and see what that particular sequence is.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|