Thread: problem with text files

  1. #16
    Registered User
    Join Date
    Jun 2006
    Posts
    12
    lol.. do I really need to explain it? please.. is there another way?
    And is that really the cause of the program error?

  2. #17
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Gather
    And is that really the cause of the program error?
    No that is not the reason that it doesn't work for you. Works fine for me. It's just stupid to read the same file 12 times and open and close it 13 times.
    Kurt

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I have no idea why on earth anyone would ask you to do that. Even for an assignment. The logic involved is no different than that from using a string or a c-style string to output repeatedly the contents of the file.

    But... it's your call. Not going to argue about that.

    I have no idea why you are having this problem only when you don't run it in debug mode. But my guess is it has probably to do with the compiler you are using and some settings getting in the way *shrug*. What do I know?...

    Regardless, test your fclose() against EOF to avoid the run-time error and then see if it did in fact print the contents of each file 12 times. If not try little things like flushing the stream before closing it or clearing the stream before opening it again... dunno. Just throwing things into the air and see if anything lands face up. It's the worst way to solve a problem. But if you get it right, then you will have more info as to why the error is occuring.

    As for keeping a file opened and going back and forth to print its contents, read about fgetpos() and fsetpos()
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Gather
    lol.. do I really need to explain it? please.. is there another way?
    And is that really the cause of the program error?
    If this is for a secret project? Something like a secret weapon against the imminent alien invasion? Or maybe a global satellite hacking mechanism? Or better yet, a new secret recipe for almonds?

    If it is, then don't share. Highly sensitive information should never be shared in the net.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #20
    Registered User
    Join Date
    Jun 2006
    Posts
    12
    Quote Originally Posted by Mario F.
    If this is for a secret project? Something like a secret weapon against the imminent alien invasion? Or maybe a global satellite hacking mechanism? Or better yet, a new secret recipe for almonds?

    If it is, then don't share. Highly sensitive information should never be shared in the net.
    loool.. well.. its closest to the almond recipe, but it has no secret.. and it has nothing to do with food.. and.. its not a recipe.
    i'ts just a project/assignment where the program determines the language of a text file using 6 dictionaries of diferent languages. This is just a part of the project.
    This part is suposed to compare the text with the dictionaries to count the number of equal words between the text and each dictionary.

    the "count=11" was just an example.. but its really the number of words in the text (counted previously). it's used so that it compares each word in the text with each word in each dictionary. that's why i have 2 FORs and a WHILE...

  6. #21
    Registered User
    Join Date
    Jun 2006
    Posts
    12
    Quote Originally Posted by Mario F.
    Regardless, test your fclose() against EOF to avoid the run-time error and then see if it did in fact print the contents of each file 12 times. If not try little things like flushing the stream before closing it or clearing the stream before opening it again... dunno.
    what do you mean? flushing the stream?

    other thing i forgot to mention.. the program is giving the error when i do the fclose(fin) for the second time. =X

  7. #22
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    fflush() if you insist on using the standard C IO functions (<stdio.h>), or

    &flush() if you want to become slightly cooler and draw lots of friends (<iostream.h>), or

    &flush() from <iostream>, to have people begging to touch you.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #23
    Registered User
    Join Date
    Jun 2006
    Posts
    12
    Quote Originally Posted by Mario F.
    fflush() if you insist on using the standard C IO functions (<stdio.h>), or

    &flush() if you want to become slightly cooler and draw lots of friends (<iostream.h>), or

    &flush() from <iostream>, to have people begging to touch you.
    THKS.. that solved it lol.. i'll put your name in my final presentation.. xP

  9. #24
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Glad to know it solved it.
    However, I'm afraid it's kinda of a hacked solution. fclose() is supposed to flush the stream. Don't know why it was not doing it.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #25
    Registered User
    Join Date
    Jun 2006
    Posts
    12
    man.. i'm getting really crazy with this program!!!
    everything was going fine.. then i tested the program with various text files.. and sometimes the same error apears at the fclose().. sometimes another error apears when the WHILE starts!!!

    i'm just using files with little normal words.. separated by end of line

  11. #26
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Your second fopen() doesn't have a check to see if the file was opened. I don't know if you've changed your code since then. Post your latest code.

    You might want to look at rewind() (a C function that sets the file pointer back at the beginning of the file) or fseek() (puts the file pointer whereever you want it) or ftell() (tells you where you are in the file so you can tell fseek() where you want to go later).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    while ((fscanf(fin,"%s",wordtxtfile))!=EOF)
    Your test should be
    Code:
    while ((fscanf(fin,"%s",wordtxtfile)) == 1)
    since fscanf() can return values other than EOF on error.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #28
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I have it! You're trying to access txtfile[x][11], and txtfile was declared as
    Code:
    txtfile[2][11]
    You should be getting a segmentation fault.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. C: include files problem
    By threahdead in forum Linux Programming
    Replies: 4
    Last Post: 05-07-2004, 08:02 AM
  5. Problem with static text in dialog boxes
    By Clyde in forum Windows Programming
    Replies: 11
    Last Post: 05-28-2002, 12:51 PM