Textbox to File

This is a discussion on Textbox to File within the Windows Programming forums, part of the Platform Specific Boards category; Hullo I'm trying to read several pieces of text from various textboxes, and throw them into a textfile on separate ...

  1. #1
    Epo is offline
    Registered User
    Join Date
    Jun 2003

    Question Textbox to File

    Hullo I'm trying to read several pieces of text from various textboxes, and throw them into a textfile on separate lines, here's what I'm using so far:

    struct QuestionTemplate
        char Q[1000];	//Holds the Question
        char A[250];	//Holds the Answer
    QuestionTemplate NewQ;
    Questions = fopen(Path, "a");
    GetWindowText(txQuestion, NewQ.Q, GetWindowTextLength(txQuestion) + 1);
    fprintf(Questions, NewQ.Q);
    GetWindowText(txAnswer, NewQ.A, GetWindowTextLength(txQuestion) + 1);
    fprintf(Questions, NewQ.A);
    The problem is that it writes it all to one line, and I'm hoping to get various lines in there. Is there something I have to concatenate to the end of the character arrays? And, if so, what would it be?


  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    You should be using fstreams, and you're using fprintf improperly.
    fprintf(Questions, "%s\n", NewQ.Q);
    Also, you should check to make sure there were no errors while opening the file.
    #include <cassert>
    Questions = fopen(Path, "a");
    assert( Questions != NULL );
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    You should try the Windows Forum for such questions, as you are likely to get more replies.

    It looks like to me that GetWindowText() returns a null terminuated string from the text box, so if you wish to print each text box string on a new line, you will have to print the new line character yourself. Give it a shot, and let me know if it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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