473,756 Members | 3,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(contr ol_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(linei n,"$ Nodes of the Entire Model") == 0){
while((control_ char=inoutFile. get()) != '$'){ // read until
the other block

inoutFile.ignor e(std::numeric_ limits<std::str eamsize>::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 3045
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(contr ol_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
1781
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') >>> f.write('dan\n') >>> f.write('pat\n') >>> f.close()
22
61406
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: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
7
3379
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! -- Regards, Webster
20
33068
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. From here read a character, print it, move the file pointer (FILE*) to 2 steps back (using fseek(fp, -2, SEEK_CUR)) to read the previous character. This seems to be ok if the file has a single line (i.e. no new line character). The above logic...
28
9583
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
1790
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 read functions. -Siliconwafer
40
4598
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 line at a time and print it out. How can I do this? I wrote the code below but it's not correct since the fscanf reads one word (terminating in whitespace or newline) at a time, instead of reading the whole line. #include <stdio.h> void...
20
2643
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
2423
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 doe", with a space in it). For console input, cin.getline(var, howMuchIWant) or cin.get() has done the trick for me in the past. It doesn't seem to work for me nearly so well with a file stream. I wouldn't have thought cpp regarded
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.