[fscanf][fseek][ftell][C language] fscanf to scan a file, but the file is no data inside.
/*
《Sample of C Program》
function: stdio.h --> How to use fscanf()
Explain : Use fscanf to scan a file,
But the file is no data inside.
Must add more function to determine.
Author:FKC
Date:2013/03
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fPtr;
int TEST;
fPtr = fopen("happy.txt", "r");
if (!fPtr) {
printf("Open File Failure...\n");
exit(1);
}
fseek(fPtr, 0, SEEK_END);
if (ftell(fPtr) == 0)
{
printf("No Data");
}
else
{
fscanf(fPtr, "%d",&TEST);
printf("%d\n",TEST);
}
fclose(fPtr);
return 0;
}
Reference :
0 意見:
張貼留言