Thread: Textbox to File

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    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:

    Code:
    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?

    Thanks

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You should be using fstreams, and you're using fprintf improperly.
    Code:
    fprintf(Questions, "%s\n", NewQ.Q);
    Also, you should check to make sure there were no errors while opening the file.
    Code:
    #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
    Posts
    278
    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, 04:54 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03: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, 08: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