c - Abort trap:6 for fopen -


i'm trying read in file called "pg.txt" , print out content, , getting abort trap:6 error. don't understand why getting it.

here main file:

#include <stdio.h> #include <stdlib.h> #include <ctype.h>  int main(){    char s1[10];    int d1;    int n1;    int n2;    int n3;    int n4;     file * fp;     fp = fopen ("pg.txt", "r");    int i;    fscanf(fp, "%d", &d1);    printf("numtypes |%d|\n", d1 );    (i = 0; < d1; i++){      fscanf(fp, "%s %d %d %d %d", s1, &n1, &n2, &n3, &n4);      printf("type1 |%s|\n", s1 );      printf("avg cpu |%d|\n", n1 );      printf("avg burst |%d|\n", n2 );      printf("avg interarrival |%d|\n", n3 );      printf("avg io |%d|\n", n4 );    }     printf("before closing\n");    fclose(fp);     return(0); } 

and pg.txt file:

2 interactive 20 10 80 5 batch 500 250 1000 10 

this output:

numtypes |2| type1 |interactive| avg cpu |20| avg burst |10| avg interarrival |80| avg io |5| type1 |batch| avg cpu |500| avg burst |250| avg interarrival |1000| avg io |10| before closing abort trap: 6 

i'm new c, explanation , highly appreciated.

the problem s1 didn't have space allocated. once s1[10] changed s1[12], there no more abort traps.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -