THis is some code I was writing to open a txt file and read the numbers in. It compiles fine but when I run it the console only comes up for a split second and then disappears again. If anyone wants to look over it and post back a solution it would be greatly appreciated. I am trying to read in 5 numbers form a txt file hence the f1....f5.
Code:
/* Reading formatted file data with fscanf(). */
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
float f1,f2,f3,f4,f5;
FILE *fp;
if ((fp=fopen("input.txt", "r"))==NULL)
{
fprintf(stderr, "Error opening the file.\n");
exit(1);
}
fscanf(fp, "%f %f %f %f %f", &f1,&f2,&f3,&f4,&f5);
printf(" The values are %f,%f,%f,%f, and %f\n.", f1,f2,f3,f4,f5);
getchar();
fclose(fp);
return 0;}