Click to See Complete Forum and Search --> : Writing to a file


ProgrammingAce
01-24-2003, 10:28 PM
I used the following statement to create a file:
hFile = CreateFile(_T("\\My Documents\\DataFile.txt"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

The file appears in the proper directory as "DataFile", so I am assuming that the file has been created successfully and that the PocketPC OS hides the file extension. However, I know know how to write to that file. I am using the WriteFile function but have been unable to pass my string to lpBuffer (type is LPCVOID)properly.
WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL);

Can someone explain how I pass my string to the WriteFile function properly?

ProgrammingAce
02-01-2003, 07:55 PM
Okay, I figured out how to write data to a file by using the WriteFile() function. The statement is: WriteFile(hDataFile, &Byte, 1, &dwBytesWritten, NULL);

But now I am trying to expand this statement so that I can write a string and a value to a file in the same statement. Ideally, I would like to write something like "I am YEARS years old.". I tried to do the following but it didnt work correctly.

//*******************
TCHAR string1 = "I am";
int YEARS;
TCHAR string2 = "years old."
LENGTH = strlen(string1) + 1 + strlen(string2);

WriteFile(hDataFile, TEXT("%s %d %s/n", string1, YEARS, string2, LENGTH, &dwBytesWritten, NULL);
//********************

Anyone have any suggestions or another method to do this?