so i am designing some software to prompt the user to enter their account number which in turn leads them to have to input their usage of ln. this then is to be displayed in a database file. i have all the code done for this. it reads in the input correctly from the user and the graphical user interface works well. however i am running into problems with the output in the text file.

just for an example lets say the account number is 678678 and their usage is 56 mL.

the output file should read...

678678 56

and then go to a new line. however it is writing in as...
678678

Wa56
Wa

i have no clue where those Wa's are coming from. please help. i thought i was formatting it correctly.

//date found to assign as filename for database
    char date[40];
    time_t now = time(0);
    struct tm* tm = localtime(&now);
                     
    //formatting date
    sprintf(date,"%04d%02d%02d.txt", tm->tm_year+1900,tm->tm_mon+1, tm->tm_mday);
    
    //opens database file with that days date
    fstream out(date, ios::out | ios::app);

	switch(msg)
	{
        case WM_INITDIALOG:
		break;
		
	  case WM_COMMAND:
		switch(LOWORD(wParam))
		{
                //click button LN this stores the account number and opens another window for further info                  
		   case IDC_LN:
		   {
                     char lnAccount[6]; 
                     int length; 
                     
                    //checks that the length of the account number 
		  length = (WORD) SendDlgItemMessage(hwnd, IDC_ACCOUNT, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); 
                    
                    //account number cant be longer than 6
                    if (length > 6) 
                    { 
                        MessageBox(hwnd, "Too many characters.", "Error", MB_OK); 

                        EndDialog(hwnd, TRUE); 
                        return FALSE; 
                    } 
                    else if (length == 0) 
                    { 
                        MessageBox(hwnd, "No characters entered.", "Error", MB_OK); 
                    }

                    // Get the characters. 
                    GetDlgItemText(hwnd, IDC_ACCOUNT, lnAccount,length+1);
      
                     //output to database file         
                     out.write(lnAccount,length);
                     out.write("\t",4);
                     out.flush();               
                     
                     //hides welcome window and opens LN window
                     ShowWindow(g_hToolbar, SW_HIDE);
				     ShowWindow(lnToolbar, SW_SHOW);	
				    
				    //click button enter to store the amount of ln used
	           case IDC_LN_ENTER:
                    {     
                         int lengthAM; 
                         //checks that the length of the of the ammount 
                         lengthAM = (WORD) SendDlgItemMessage(hwnd, IDC_LN_AMOUNT, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0);
                    	
                    	 char lnAmount[lengthAM];
                    	 
                    	 // Get the amount
                         GetDlgItemText(hwnd, IDC_LN_AMOUNT, lnAmount,lengthAM+1);
                         
                         //writes the amount of ln to be used
                    	 out.write(lnAmount,lengthAM);
                    	 out.write("\n",4);
                    	 out.flush();
                    	 
                         	
                    	 
                    }
                    break;     
               }	
               break;

sorry it looks like the indentation got a little screwed up but it should still be able to be followed. if there are any questions please ask. and thank you in advance.

These are the faulty lines:

out.write("\t",4);
..
out.write("\n",4);

Where is the 4 coming from? The length of "\t" is 1. The "Wa" is probably corresponding to some memory that is stored after the literal "\t" and "\n" which both take 2 bytes (one is \t or \n and the other is the null-character) so the compiler probably reuses the same chunk of memory so the same two extra characters "Wa" appear in each case. So "Wa" is probably the first two characters of another literal string somewhere near in the code.

Edited 6 Years Ago by mike_2000_17: n/a

thanks that fixed that problem i had a feeling it had to do with the size. the only thing now is that the output is now

678678
56

instead of...

678678 56

shouldnt the \t be tabbing the output and not starting a new line?

This question has already been answered. Start a new discussion instead.