[Solved] Processing Input file in c


I am unsure what problems you are having exactly but I can see the following errors in the code:

  • In the initialise_list() function the for loop will be iterating too many times and going beyond the bounds the of array:

    for(int i = 0; i < sizeof(list); i++) {
    

as sizeof(list) will return the number of bytes occupied by the array which is 20 * sizeof(struct job). Change to:

    for(int i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
  • this is a missing left parenthesis from fopen() attempt (meaning the posted code does not compile):

    if( (input = fopen(inputfile, "r") == NULL )
    

should be:

    if( (input = fopen(inputfile, "r")) == NULL )
  • proj is an initialised char* and this will mostly likely cause a segmentation fault:

    char *proj;
    sscanf(buffer, "./%s.txt", proj);
    

4

solved Processing Input file in c