Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define FILE_MAX 255
- int main ()
- {
- char fName[FILE_MAX];
- printf("Filename:\n");
- fgets(fName, FILE_MAX, stdin);
- fName[strcspn(fName, "\n")] = 0;
- FILE *ftc;
- if ((ftc = fopen(fName, "r")) != NULL)
- {
- printf("Number of line to read:\n");
- int lnNum;
- while (scanf("%d", &lnNum) != 1 || lnNum <= 0)
- {
- printf("Please enter a valid, positive (>0) integer.\n");
- printf("Number of line to read:\n");
- }
- int il, c;
- il = 1;
- while ((c = fgetc(ftc)) != EOF)
- {
- if (c == '\n')
- {
- il++;
- }
- else if (il == lnNum)
- {
- printf("%c", c);
- }
- }
- printf("\n");
- }
- else
- {
- printf("A file was not found with the specified name, or the file found could not be accessed for reading by the program.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment