Saving and Importing text files

This is a discussion on Saving and Importing text files within the Windows Programming forums, part of the Platform Specific Boards category; I've been writing an address book and its working good, i can save the information and in the text file ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Saving and Importing text files

    I've been writing an address book and its working good, i can save the information and in the text file its formatted right, it has new lined were its suppost to in all. When i go to load the file into the multi lined edit box that i want to display it in everything after the first line doesn't show up. how would i get this to work right
    example:
    in "address.dat"
    John Doe 555 Evergreen Terris
    Jane Doe 666 No where

    the file looks fine in all but when i go and bring it into the edit box i only either get the first line with a wierd character after it or i get it all in one long string.

    Any ideas
    heres what i'm using to save the info to the file
    fprintf(AddyList,"%s %s %s %s %s\n",FirstN,LastN,HouseNumb,Street,City);

  2. #2
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    What is the code? Are you able to read it from your program? What is the editor you are reading it with? Can it handle '\n' -marks?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    The files being written fine each new entry is on a seperate line, thats because the \n worked fine, but when i open the file to view in an edit box inside my program is doesn't display anything past the first line even though its there in the program. I used the fopen fclose getf, setwindowtext getwindowtext.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>fprintf(AddyList,"%s %s %s %s %s\n",FirstN,LastN,HouseNumb,Street,City);

    Are any of these not strings ie ints? If so change the %s to a %d ect.

    Try using the win32 api file functions CreateFile(), ReadFile() WriteFile() and CloseHandle()

    If using text not binary files be carefule that each record may not be the same size. If edited and "Bob" is changed to "Roberto" will overwrite further down the file. I suggest a struct to hold the details and to save in binary file format. This can then be read back at a constant size eg sizeof(STRUCT)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    ok

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2005, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21