How to check to see if the next line is blank and ignore it (2D Array C)? -
in program has predefined constant value both rows , columns of 2d array. however, want go max number of rows , columns & skip on blank or empty lines & print "grades" (while ignoring empty 30th line) screen. i've tried incorporating fgets , sscan, poorly, got strange set of numbers. code far:
#include <stdio.h> #include <stdlib.h> #define rows 30 #define column 4 int main() { file *ip; ip = fopen("input.txt", "r"); int count1 = 0, count2 = 0; int i, j; int grades[rows][column]; for(i = 0; < rows; i++) { count2 = 0; for(j = 0; j < column; j++) { int num; if(fscanf(ip, "%d", &num) != '\0') { grades[i][j] = num; count2++; } else { count2 = 0; } } if(count2 != 0) { count1++; } } for(i = 0; < rows; i++) { for(j = 0; j < column; j++) { printf("student %d grade %d: %d\n", i+1, j+1, grades[i][j]); } printf("\n"); } fclose(ip); return 0; } my infile looks (29 rows instead of max "30"):
33 0 97 40 50 61 96 92 98 68 61 65 91 29 48 5 14 30 97 11 22 0 7 81 96 55 9 39 67 39 83 97 5 18 67 9 85 53 33 73 62 58 24 70 91 97 69 33 40 1 86 92 83 26 74 67 53 4 18 20 49 67 98 64 62 39 27 56 26 9 43 1 46 73 48 68 34 48 38 71 21 32 24 6 50 27 79 96 1 0 59 81 58 34 95 8 48 91 2 77 90 99 68 20 43 99 94 40 4 65 29 1 70 34 83 74 output:

edit
forgot mention assignment states there maximum of 30 students 4 grades each, number of actual students not specified. 29 rows, 26 rows, 20 rows, 30 rows or 15 rows. however, there 4 grades each student.
Comments
Post a Comment