zethulon's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
28 (0.04 per day)
Joined:
25-September 12
Profile Views:
456
Last Active:
User is offline Dec 06 2012 08:48 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   zethulon has not set their status

Posts I've Made

  1. In Topic: Error: Program crash

    Posted 6 Dec 2012

    View PostJackOfAllTrades, on 06 December 2012 - 05:53 AM, said:

    And what is your CURRENT code?


    My current code is the one with
    fin. getline(sentence, 100) ;
    strcpy(temp, sentence) ;
    while {}

    I believe it's my 2nd posr
  2. In Topic: Error: Program crash

    Posted 6 Dec 2012

    View Postjimblumberg, 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.
  3. 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.

    View Postsnoopy11, 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?
  4. 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?
  5. 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.

Comments

Page 1 of 1
  1. Photo

    aresh Icon

    14 Nov 2012 - 08:13
    Post your code in the C/C++ forum, and I'm sure many people can help you.
Page 1 of 1