How would I go about reading in each line of a file?
I did look at this thread, but it didn't have exactly what I wanted. What I want to do is read in 1 line which has a title, store that in a CString. Read in the next line with the author's name, store that in a CString. Then read in the writing (2 lines below author's name) and store that into a CString.
I've been searching MSDN's documents for fgets, fseek, and all the other C file functions, but none seem to be what I need. Here's the code I have so far:
Code:
void CPoetryEditorDlg::OnOpenFile()
{
// TODO: Add your control notification handler code here
FILE *fp;
poem.Empty();
author.Empty();
dt.Empty();
title.Empty();
pb.Empty();
fp = fopen(file, "r");
if(fp == NULL){
AfxMessageBox("Unable to open file for reading!");
fclose(fp);
}
fseek(fp, 0L, SEEK_SET);
fscanf(fp, "%s", title);
fscanf(fp, "%s", author);
fscanf(fp, "%s", dt);
fscanf(fp, "%s", pb);
fclose(fp);
}
If someone could even just explain the 0L in the fseek function (I got the fseek & fscan code from MSDN, but it didn't work).