Files related
-
Hello, I have created one MFC Application for User login page. I have created 2 dialog boxes. One dialog box contains username and password, when i press Create new account button, there is another dialog box will open. There i have given the username, password and confirm password. The problem is if i click the submit button in 2nd dialog, only one character has to be stored in the file. I want to store the entire text in the file. How can I do that?. Please help on this. Thanks in advance.
-
Hello, Thanks a lot for reply. I attached the source code below: If i click the submit button the following code is executing. -------------------------------------------------------------- FILE *fleCredentials; try { // Create a new file or open the existing one fleCredentials = fopen("credentials.crd", "a+"); { // Add the username to the file // fprintf(fleCredentials, "%s ", (LPCTSTR)m_Username); // Add the password to the file fprintf(fleCredentials, "%s\n", (LPCTSTR)m_Password); } // After using it, close the file fclose(fleCredentials); --------------------------------------------------------
-
Hello, I have created one MFC Application for User login page. I have created 2 dialog boxes. One dialog box contains username and password, when i press Create new account button, there is another dialog box will open. There i have given the username, password and confirm password. The problem is if i click the submit button in 2nd dialog, only one character has to be stored in the file. I want to store the entire text in the file. How can I do that?. Please help on this. Thanks in advance.
Could you please post the code snippet ? Regards, Paresh.
-
Could you please post the code snippet ? Regards, Paresh.
I have given the code snippet where i can get the problem.
-
Hello, Thanks a lot for reply. I attached the source code below: If i click the submit button the following code is executing. -------------------------------------------------------------- FILE *fleCredentials; try { // Create a new file or open the existing one fleCredentials = fopen("credentials.crd", "a+"); { // Add the username to the file // fprintf(fleCredentials, "%s ", (LPCTSTR)m_Username); // Add the password to the file fprintf(fleCredentials, "%s\n", (LPCTSTR)m_Password); } // After using it, close the file fclose(fleCredentials); --------------------------------------------------------
What is the data type of m_Username and m_Password?
-
What is the data type of m_Username and m_Password?
m_username and m_password are CString types.
-
m_username and m_password are CString types.
If you use the debugger at that function to save the two files, I bet you get... m_User = "user" and m_Pass = "pass" (I can't see your original code) And then your text file will be.... userpass with no way of know where one starts, and the other finishes... Instead of CString, try using a fixed character array, and then saving that out. It will be much easier when you load it. It will have the restriction of only being able to have user names and passwords of a certain length, so don't make it too short! Iain.
-
m_username and m_password are CString types.
Try using GetBuffer() function for the CString objects in the fprintf statement?
-
Try using GetBuffer() function for the CString objects in the fprintf statement?
No, don't do that at all. :rolleyes: The
GetBuffer()
method should only be used when write access to the internal buffer is required. In this case, it is not. TheLPCTSTR
operator is all that's needed."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hello, Thanks a lot for reply. I attached the source code below: If i click the submit button the following code is executing. -------------------------------------------------------------- FILE *fleCredentials; try { // Create a new file or open the existing one fleCredentials = fopen("credentials.crd", "a+"); { // Add the username to the file // fprintf(fleCredentials, "%s ", (LPCTSTR)m_Username); // Add the password to the file fprintf(fleCredentials, "%s\n", (LPCTSTR)m_Password); } // After using it, close the file fclose(fleCredentials); --------------------------------------------------------
How are you verifying that only two characters (one from each variable) exist in the file? Is this a Unicode application?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne