IBM developerWorks
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 29th, 2003, 02:35 PM
colpaarm's Avatar
colpaarm colpaarm is offline
300lb Bench!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2001
Location: New York
Posts: 2,191 colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 5 h 8 m 19 sec
Reputation Power: 11
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.

Reply With Quote
  #2  
Old January 29th, 2003, 02:55 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
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.

Reply With Quote
  #3  
Old January 29th, 2003, 07:15 PM
colpaarm's Avatar
colpaarm colpaarm is offline
300lb Bench!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2001
Location: New York
Posts: 2,191 colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level)colpaarm User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 5 h 8 m 19 sec
Reputation Power: 11
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.

Reply With Quote
  #4  
Old January 29th, 2003, 08:03 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
You can always look at the file in hex mode and see what that particular sequence is.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Weird character sequence at end of a few lines is messing up my c executables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway