- This topic has 1 reply, 2 voices, and was last updated 15 years, 1 month ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.
Home › Forums › C Programming › Read in from a file with specific syntax …
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!!
Heres an old program that I have that reads an int then a float on each line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/****************************************************************<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 /> } |