char * buffer = 0;
long length;
FILE * f = fopen (filename, "rb");
if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
fread (buffer, 1, length, f);
}
fclose (f);
}
if (buffer)
{
// start to process your data / extract strings here...
}
#include <stdio.h>
#define n 1024 // n bytes
int main(void) {
FILE *fp;
size_t numread;
if ((fp = fopen("yourfile.xy", "rb") != NULL) {
char buffer[n];
numread = fread(buffer, sizeof(*buffer), n, fp);
printf("Read %d Bytes: %s", numread, buffer);
fclose(fp);
return 0;
}
return -1;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE *fptr;
if ((fptr = fopen("C:program.txt","r")) == NULL){
printf("Error! opening file");
// Program exits if the file pointer returns NULL.
exit(1);
}
fscanf(fptr,"%d", &num);
printf("Value of n=%d", num);
fclose(fptr);
return 0;
}