#include<stdio.h>
void main(int argc , char *argv[])
{
FILE *file;
char *line[100];
int count = 0;
// initialise file pointer to read
file = fopen(argv[1],"r");
// read line by line
while(file , "%[^\n]\n" , line)!=EOF)
{
// break after 10 lines
if(count == 10)
{
break;
}
else
{
printf("%s\n" , line);
}
count++;
}
fclose(file);
}
output:
cc head.c
./a.out filename
void main(int argc , char *argv[])
{
FILE *file;
char *line[100];
int count = 0;
// initialise file pointer to read
file = fopen(argv[1],"r");
// read line by line
while(file , "%[^\n]\n" , line)!=EOF)
{
// break after 10 lines
if(count == 10)
{
break;
}
else
{
printf("%s\n" , line);
}
count++;
}
fclose(file);
}
output:
cc head.c
./a.out filename
Comments
Post a Comment