[ create a new paste ] login | about

Link: http://codepad.org/Pb3wJnGT    [ raw code | output | fork | 1 comment ]

C, pasted on Dec 19:
#include<stdio.h>
#include<conio.h>
#define maxN 2048

long countLines(FILE* inFile)
{
	long count = 0; char line[maxN];
	while(fgets(line, maxN - 1, inFile) != NULL)
	{
		count++;
	}
	return count;
}
void main()
{
	FILE* fp = fopen("Data.txt", "rt");
	if(fp != NULL)
	{
		long cnt = countLines(fp);
		printf("\nSo dong trong van ban = %d\n", cnt);
	}
	getch();
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'main':
Line 15: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments:
posted by mouto9k on Feb 14
Do hàm fgets dung khi gap ki tu xuong dong hoac het n - 1 ki tu
reply