Advertisement
TheQuack45

C print file line number

Jun 6th, 2016
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. main ()
  4. {
  5.     FILE *fileToCount;
  6.     fileToCount = fopen("testfile.txt", "r");
  7.  
  8.     int lnNum;
  9.     scanf("%d", &lnNum);
  10.    
  11.     int il, c;
  12.     il = 1;
  13.     while ((c = fgetc(fileToCount)) != EOF)
  14.     {
  15.         if (c == '\n')
  16.         {
  17.             il++;
  18.         }
  19.         else if (il == lnNum)
  20.         {
  21.             printf("%c", c);
  22.         }
  23.     }
  24.    
  25.     printf("\n");
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement