c - How do I get the file to print to the screen? -


i trying data quiz_scores.txt print screen can scan array don't know how. need hard-code file program , if how?

#include <stdlib.h> #include <stdio.h> #include <strings.h>  int main(void) {     //initializing variables      file *es;     file *hs;     int num=0;     int i;     int j;     int cols=10;     int rows=10;     int qid, s;     int quizarray[0][0];     int max_length=15;     char *result0;     char line[max_length];     file *qs="c:\\quiz_scores.txt";      qs = fopen("quiz_scores.txt", "r");      /*for (i=0; i<cols; i++){         (j=0; j<rows; j++){             quizarray[i][j]=0;             fscanf(qs, "%d%d", quizarray[i][j]);         }     } */      while(fgets(line, max_length, qs))     {         printf("%s", line);     }     if(qs == null)     {         printf("error: not open file\n");         return -1;     }     /*for (i=0;i<n;i++)     {         fprintf(qs, "%d\n");     }     fclose(qs);*/     return 0; } 

ok think know want happen, read numbers file quiz_scores.txt 2d array , print them,correct?. hope these corrections allow , understand why wouldn't work before. rest of program yourself, luck!!

    #include <stdlib.h>     #include <stdio.h>     #include <strings.h>  int main(void) {     //initializing variables     int num=0,i,j,cols=10,rows=10;//just smooshed onto same line cause annoying me     int quizarray[10][10];//you declared 2d array 0 elements(you wanted 1 ten rows , columns presume 10 teams 10 rounds)     file *qs = fopen("quiz_scores.txt", "r");//your declaration of file pointer incorrect     if(qs == null)//this if needs go before read file otherwise kind of redundant     {         printf("error: not open file\n");         return -1;     }      (i=0; i<cols; i++)     {         (j=0; j<rows; j++)         {             quizarray[i][j]=0;             fscanf(qs,"%d", &quizarray[i][j]);//them scanfs need &s mate               \\and don't try scan in 2 integer 1 array element             printf("%d",quizarray[i][j]);             if(j<rows-1)                 printf("-");         }         printf("\n");     }      fclose(qs);//dont comment fclose out bad things happen :p     return 0; } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -