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;