Home › Forums › C Programming › Read in from a file with specific syntax …
- This topic has 1 reply, 2 voices, and was last updated 17 years ago by Humayan.
Viewing 1 reply thread
- AuthorPosts
- December 10, 2007 at 9:16 pm #2044totonParticipant
Hello, thank you for taking the time to review my problem. I’m trying to read in from a file which has specific syntax (shown below) and recognize part1 and part2. It should compare part1 with an internal value to be returned from later code. In short:
The file will consist of the following:
part1:part2
etc…
I need to read each line and recognize part1 as a variable and part2 as a variable (seperated by the colon, which is to be ignored). If I can get that working, I have the rest sorted out (i think). All feedback is greatly appreciated!! - December 13, 2007 at 2:42 pm #3292HumayanParticipant
Heres an old program that I have that reads an int then a float on each line:
12345678910111213141516171819202122232425262728293031/****************************************************************<br />* File Name : cgt.cpp<br />* Date : April,18,2006<br />* Comments : new project<br />* Program Shell Generated At: 10:33:48<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br />#include <br />#include <br /><br />int main()<br />{<br />ifstream inputFile ( "c:\programs\CSC2133N.TXT" );<br />if ( inputFile.fail() ) //check if file opened<br />{<br />cout << "File Did Not Open!" << endl;<br />return 1;<br />}<br /><br />int i;<br />double d; //use better names here!!!!!<br /><br />inputFile >> i;<br />while ( ! inputFile.eof() )<br />{<br />inputFile >> d;<br />cout << i << " " << d << endl;<br />inputFile >> i;<br />}<br />inputFile.close();<br />return 0;<br />}
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.