Here are a couple of problems with this code 1) GetBuffer() memory has to be released with ReleaseBuffer 2) fwrite( strTitleCurrentDate, sizeof(TCHAR), strTitle.GetLength()/** sizeof( TCHAR )*/, fp ); How do you decide to write strTitleCurrentDate to the length of strTitle, they are not related ... Correction strTitleCurrentDate.GetLength() 3) Here is even more ambiguous code CString strTitle1; newBuffer=strTitle1.GetBuffer(strTitle1.GetLength()* sizeof( TCHAR )); What is the size of allocation ? strTitle1 is a zero length string! Zero and you decide to read fread( newBuffer, sizeof(char), 100/** sizeof( TCHAR )*/, fp ); 100 bytes to this buffer. Shouldn't this be fread( newBuffer, sizeof(TCHAR), strTitle1.GetLength(), fp ); if your allocation was right ? However it should be just TCHAR myFileBuffer[1024]; fread( myFileBuffer, sizeof(TCHAR), 1024, fp ); why use GetBuffer ? Remember when dealing with a char pointer, when you cross what you have allocated, you are writing in to other non allocated memory. You have to always allocate for the string terminator. Any such memory overwrite results in crash, usually later in the code. How to use google type "how to read a text file line by line" and see the google results, open the second link and it has the following piece of code for a similar task. Please modify this code to get your stuff done. So another advice, try to use google much more with different search strings representing the same question. #include #include #include using namespace std; int main() { char buffer1[2048]; char buffer2[2048]; istrstream ostr1(buffer1, 2048); istrstream ostr2(buffer2, 2048); int values1[100]; int values2[100]; int c=0; ifstream fin("data.txt"); fin.getline(buffer1, 2048); fin.getline(buffer2, 2048); while (ostr1 >> values1[c]) { ostr2 >> values2[c++]; } for (int i=0;iLive and let live :)