zethulon's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 28 (0.1 per day)
- Joined:
- 25-September 12
- Profile Views:
- 186
- Last Active:
Dec 06 2012 08:48 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Error: Program crash
Posted 6 Dec 2012
-
In Topic: Error: Program crash
Posted 6 Dec 2012
jimblumberg, on 06 December 2012 - 05:59 AM, said:Are you required to use character strings? Can you use std::string instead?
Actually the way you are using your eof() is correct, you have a priming read before the loop and are reading your line at the end of the loop. But normally I recommend using the read itself to control the loop. For example:
while (fin.getline(sentence, 100)) { strcpy(temp, sentence); cout << temp << endl; strcpy(atest, strtok(temp, "\"\t") ); strcpy(btest, strtok(NULL, "\"\t") ); strcpy(ctest, strtok(NULL, "\"\t") ); strcpy(dtest, strtok(NULL, "\"\t") ); cout << atest << " " << btest << " " << ctest << " " << dtest << endl; }
This way you test for all of the different possible stream failures instead of just eof().
Jim
I am required to use c strings because I would like to get the strings inside the double quotation marks. Idk the other ways I can do so. -
In Topic: Error: Program crash
Posted 6 Dec 2012
I would also like to change what I said before. The program is not displaying what I meant for it to display.
I am expecting for the program to display this:
"ALPHA" "DELTA" "MAGMA" "PATERNUS"
ALPHA DELTA MAGMA PATERNUS
"OMEGA" "SIGMA" "GLACIER"
OMEGA SIGMA GLACIER
The problem is I am not getting the last line. However when I changed the content of the
Input file so that the last set of double quotation marks will have something inside, the program will successfully display the 4th line.
snoopy11, on 05 December 2012 - 11:46 PM, said:Hi,
You are reading beyond the end of file
try changing fin.eof to
while ( fin.good() )
{
Best Wishes
Snoopy.
Why doesn't. ! fin. eof() prevent reading beyond end of file? -
In Topic: Error: Program crash
Posted 6 Dec 2012
Is my use of strtok appropriate. If not how would I store the Contents of Tok to different variables? -
In Topic: Error: Program crash
Posted 5 Dec 2012
Could someone please tell me any possible errors. Thank you.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
zethulon hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
aresh
14 Nov 2012 - 08:13