Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int getRowsCount(FILE *pFile);
- int main(int argc, char **argv)
- {
- int rows;
- FILE *pFile = NULL;
- char filename[255];
- printf("Zadejte vstupni soubor: ");
- scanf("%s", filename);
- pFile = fopen(filename, "rt");
- if (pFile != NULL)
- {
- rows = getRowsCount(pFile);
- printf("Soubor obsahuje %d radku\n", rows);
- }
- else
- {
- printf("Soubor %s se nepodarilo otevrit\n", filename);
- return 0;
- }
- fclose(pFile);
- return 0;
- }
- int getRowsCount(FILE *pFile)
- {
- int rows = 0;
- int c;
- do
- {
- /* ctu znak po znaku */
- c = fgetc(pFile);
- /* hledam radky */
- if (c == '\n')
- rows++;
- } while (c != EOF);
- /* presunu se na zacatek souboru */
- fseek(pFile, 0, SEEK_SET);
- return rows;
- }
Add Comment
Please, Sign In to add comment