I'm trying to read a file "data.txt" with a single line "00:612:33188" (each number represents a field of data, "changes:size:permission"), and write that information into a struct. I want to write the code in general for any number of characters in those fields.
My question is regarding the use of fscanf. I cannot seem to make it work. The following code produces a segmentation fault error.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXHITS 50
#define FIELDMAX 100
#define TOTALELEMENTS 100000
typedef struct Elements{
  char changes[FIELDMAX];
  char size[FIELDMAX];
  char permission[FIELDMAX];
} Elements;
int main(int argc, char const *argv[]) {
  if(argc < 2) {
       printf("\nSyntax: fscanf data\n\n");
       exit(EXIT_FAILURE);
  }
  Elements total[TOTALELEMENTS];
  Elements hits[MAXHITS];
  int total_elements = 0;
  int total_hits = 0;
  FILE *fp;
  // open the file and scan each field copying to the corresponding struct
  fp = fopen (argv[1], "r");
  if (fp){
    fscanf(fp,"%99s:%99s:%99s", total[total_elements].changes,
    total[total_elements].size, total[total_elements].permission);
    printf("%s\n%s\n%s\n", total[total_elements].changes,
    total[total_elements].size, total[total_elements].permission);
    fclose (fp);
  }
  return 0;
}
 
     
    