Guest User

Untitled

a guest
Apr 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int getRowsCount(FILE *pFile);
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. int rows;
  9. FILE *pFile = NULL;
  10. char filename[255];
  11.  
  12. printf("Zadejte vstupni soubor: ");
  13. scanf("%s", filename);
  14.  
  15. pFile = fopen(filename, "rt");
  16.  
  17. if (pFile != NULL)
  18. {
  19. rows = getRowsCount(pFile);
  20.  
  21. printf("Soubor obsahuje %d radku\n", rows);
  22. }
  23. else
  24. {
  25. printf("Soubor %s se nepodarilo otevrit\n", filename);
  26. return 0;
  27. }
  28.  
  29. fclose(pFile);
  30.  
  31. return 0;
  32. }
  33.  
  34. int getRowsCount(FILE *pFile)
  35. {
  36. int rows = 0;
  37. int c;
  38.  
  39. do
  40. {
  41. /* ctu znak po znaku */
  42. c = fgetc(pFile);
  43.  
  44. /* hledam radky */
  45. if (c == '\n')
  46. rows++;
  47.  
  48. } while (c != EOF);
  49.  
  50. /* presunu se na zacatek souboru */
  51. fseek(pFile, 0, SEEK_SET);
  52.  
  53. return rows;
  54. }
Add Comment
Please, Sign In to add comment