34 lines
531 B
C
34 lines
531 B
C
#include <stdio.h>
|
|
|
|
#define SIZE_LINE 1000+1
|
|
|
|
int countLine(FILE * file);
|
|
|
|
int main(void) {
|
|
FILE * file = fopen("file.txt", "rt");
|
|
|
|
if (file != NULL) {
|
|
int countRow = 0;
|
|
|
|
countRow = countLine(file);
|
|
|
|
printf("Number of character: %d\n", countRow);
|
|
|
|
fclose(file);
|
|
} else {
|
|
perror("Error (source)");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int countLine(FILE * file) {
|
|
int countRow = 0;
|
|
char line[SIZE_LINE];
|
|
|
|
while (fgets(line, sizeof(line), file) != NULL) {
|
|
countRow++;
|
|
}
|
|
|
|
return countRow;
|
|
} |