I am learning C for university and I am stuck on a question.
I am trying to achieve the following.
1. Read Data from file - This works
Expand|Select|Wrap|Line Numbers
- int readfile()
- {
- FILE *fptr;
- char filename[15];
- char ch;
- printf("Enter the filename to be opened \n");
- scanf("%s", filename);
- /* open the file for reading */
- fptr = fopen(filename, "r");
- if (fptr == NULL)
- {
- printf("Cannot open file \n");
- exit(0);
- }
- ch = fgetc(fptr);
- while (ch != EOF)
- {
- ch = fgetc(fptr);
- }
- fclose(fptr);
- }
3. Perform mathematical calculation on the values. - this is done, albeit manual entry at the moment.
The data is stored as per below:
x,y
x1,y1
x2,y2
...
xn,yn
The data also varies in size (so the file could be 30 lines of x and y co-ordinates, or 100).
Any pointers would help.
Thanks