Hi,
I have a text file which looks in the following format
=====c:\text.txt ======
AAAA
BBBB
...
...
==================
I have to read each line of the text file into a buffer, and print it, which I did in the following way.
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#define MAX_LENGTH 256
int _tmain(int argc, _TCHAR* argv[])
{
FILE *pF; //pF to pointer to the text file
char pBuff[MAX_LENGTH]; //Buffer to get each line
int i = 0;
int f=0,nf=0;
pF = fopen("c:\\text.txt", "r"); //opening in read mode
while(fgets(pBuff , MAX_LENGTH , pF))
{
if(strcmp(pBuff,"")!=0) //to discard empty lines
{
int len = strlen(pBuff);
pBuff[dbLen-1] = '\0';
printf("%s::%d\n", pBuff,len);
}
}
fclose(rFile);
}
return 0;
}
but, I want to do the same stuff using Win32 APIs :( where I m naive.
But I proceeded in the following way..
created a File handle for the text file to read like this.
HANDLE hFile;
hFile = CreateFile(L"C:\\test.txt",GENERIC_READ,
FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
Now, could any one help me out to which API to be used, to proceed further..
I thought of doing like,
1. get the file size
2. create a char* and allocate the size of file size
3. copying the entire file into a string buffer using Readfile() API, and process the buffer character by character for '\n' and print it to console..
but I think this is not ideal, so is there any other way to do it better..
Thanks in advance
-vijay