so i have this problem reading data using sscanf, it seems that sscanf read the same buffer the same way, so that it always start at the beginning of the buffer. When i tried to read data for the 2d score array it read in the elements number which is the beginning of the buffer as i read them in second sscanf how do i fix this code so that i would read the score instead of the element numbers?Code:#include <stdio.h> #include <stdlib.h> #define MAX 21 #define MAX_ELEM 8 #define SCORE 12 #define NUM_SKATER 4 #define BASE 3.1 typedef struct{ char name[MAX]; int elements; float baseval[MAX_ELEM]; int score[MAX_ELEM][SCORE]; float total_base; float tech_score; float total_score; }SKATER; int getData(SKATER skater[NUM_SKATER]); void calcData(SKATER skater[NUM_SKATER]); void insertSort(SKATER skater[NUM_SKATER], int num); void printData(SKATER skater[]); int main (void) { // Global Declarations SKATER skater[NUM_SKATER]; int num; // Funtion calls num = getData(skater); calcData(skater); insertSort(skater, NUM_SKATER); printData(skater); return 0; } /********************************* getData ************************************ Pre: Post: */ int getData(SKATER skater[NUM_SKATER]) { // LOcal Declarations FILE* fpIn; int i = 0; int k; int j; char buffer[256]; // Statements if((fpIn = fopen("lab6data.txt","r"))==NULL) { printf("File opening error"); system("PAUSE"); exit(100); } while(i < NUM_SKATER && fgets(buffer, sizeof(buffer) - 1, fpIn)) { sscanf(buffer,"%*c%19[^0123456789]", skater[i].name); for(k = 0; k < MAX_ELEM; k++) { if(fgets(buffer, sizeof(buffer)-1, fpIn) != NULL) { sscanf(buffer,"%d %f", &skater[i].elements, &skater[i].baseval[k]); for(j = 0; j < SCORE; j++) { sscanf(buffer,"%d", &skater[i].score[k][j]); } } } i++; } system("PAUSE"); fclose(fpIn); return i; }
the input data is in the link
Ideone.com | Online C Compiler & Debugging Tool
one each line the first number being the element number the second is the base val and the rest is the scores
thanks