473,396 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File reading problem probably newline character

Hi there I am trying to read from a file,
I am trying to read certain fields,there are 6 fields in this file like

--------/--------/--------/--------/--------/--------/

All fields are 8 characters width and I am comparing the first
character of the line with the $ sign which seperates different blocks
of information

$ Nodes of the Entire Model
GRID 1 .25 .25 0.
GRID 2 .2 .25 0.
GRID 3 .15 .25 0.
GRID 4 .1 .25 0.
GRID 5 .05 .25 0.
GRID 6 0. .25 0.
GRID 7 .25 .2 0.
GRID 8 .2 .2 0.
GRID 9 .15 .2 0.
GRID 10 .1 .2 0.
GRID 11 .05 .2 0.
GRID 12 0. .2 0.
GRID 13 .25 .15 0.
GRID 14 .2 .15 0.
GRID 15 .15 .15 0.
GRID 16 .1 .15 0.
GRID 17 .05 .15 0.
GRID 18 0. .15 0.
GRID 19 .25 .1 0.
GRID 20 .2 .1 0.
$ Loads for Load Case : Default

I can read the first line of the input which is GRID 1 .... and
the result is 'G'
after that reading the first charecter(control_char in the code) on the
newline results in (-1 and y with two dots on top of y) I could not
figure out my problem. My code for this part is
..
..
..
while(inoutFile.getline(linein,80,'\n')){
if(strcmp(linein,"$ Nodes of the Entire Model") == 0){
while((control_char=inoutFile.get()) != '$'){ // read until
the other block

inoutFile.ignore(std::numeric_limits<std::streamsi ze>::max(),'\n');
}
}
if(control_char=='$')
break;
}
..
..
..

Can there be a problem related with binary and text files? Because the
file I am trying to read is the output of a package program and I do
not know the newline characters that are used to these files. (I also
tried it with a file that I know the newline character is '\n', the
same problem still persists with the file I created myself as well :-((
)

Any help will be appreciated.

Thanks.

Mar 13 '06 #1
1 3009
TB
utab skrev:
Hi there I am trying to read from a file,
I am trying to read certain fields,there are 6 fields in this file like

--------/--------/--------/--------/--------/--------/

All fields are 8 characters width and I am comparing the first
character of the line with the $ sign which seperates different blocks
of information

$ Nodes of the Entire Model
GRID 1 .25 .25 0.
GRID 2 .2 .25 0.
GRID 3 .15 .25 0.
GRID 4 .1 .25 0.
GRID 5 .05 .25 0.
GRID 6 0. .25 0.
GRID 7 .25 .2 0.
GRID 8 .2 .2 0.
GRID 9 .15 .2 0.
GRID 10 .1 .2 0.
GRID 11 .05 .2 0.
GRID 12 0. .2 0.
GRID 13 .25 .15 0.
GRID 14 .2 .15 0.
GRID 15 .15 .15 0.
GRID 16 .1 .15 0.
GRID 17 .05 .15 0.
GRID 18 0. .15 0.
GRID 19 .25 .1 0.
GRID 20 .2 .1 0.
$ Loads for Load Case : Default

I can read the first line of the input which is GRID 1 .... and
the result is 'G'
after that reading the first charecter(control_char in the code) on the
newline results in (-1 and y with two dots on top of y) I could not


ÿ

I'd guess you hit the end of the file. You need to check if the stream
is still valid after each extraction.

<snip>

--
TB @ SWEDEN
Mar 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kevin T. Ryan | last post by:
Hi All - I'm not sure, but I'm wondering if this is a bug, or maybe (more likely) I'm misunderstanding something...see below: >>> f = open('testfile', 'w') >>> f.write('kevin\n') >>>...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
7
by: Webster | last post by:
Hello, I have to read a file with a single "command" per line. But how do I read to the end of the line?? I am using C style filepointers (not by choice :( ) Thanks for any help! --...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
28
by: Colin JN Breame | last post by:
Hi, Fairly new to C. What is the best way to read a line (\n terminated) from a file? Ive looked at fscanf but was not sure which format specifier to use. (%s perhaps). Thanks Colin
8
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
20
by: plmanikandan | last post by:
Hi, I need to read a file line by line.each line contains different number of characters.I opened file using fopen function.is there any function to read the file line by line Regards, Mani
9
by: sherifffruitfly | last post by:
Hi, I've a got a little (exercise) program that reads data from a file and puts it into struct members. I run into trouble when one of the data pieces is comprised of several words (eg "john...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.