Segmentation fault when reading from file

Discussion in 'C' started by hari.sarvothama, Aug 28, 2010.

  1. <div>The aim of the program is to read contents from 2 files and store it in struct variables.(This is actually a part of another program which stimulates pass2 of two pass assembler)

    This code works fine.

    #include
    #include
    #include
    struct optbl
    {
    char opco[10];
    int value;
    }o_tbl[100];
    struct symtbl
    {
    char sym[10];
    int addr;
    }s_tbl[100];
    int count=0,n=0;
    main()
    {
    int i;
    char a[100];
    FILE *fp2;
    fp2=fopen("OP_TBL.TXT","r");
    if(fp2)
    printf("Opened");
    while(1)
    {
    fscanf(fp2,"%s",a);
    if(feof(fp2))
    break;
    strcpy(o_tbl[count].opco,a);
    fscanf(fp2,"%s",a);
    if(feof(fp2))
    break;
    o_tbl[count++].value=atoi(a);
    }
    for(i=0;i
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice