Hi,
I'm trying to write a program which just reads from a file and prints the characters on the screen, plz take a look at the code and tell me whats wrong
Code:
# include <stdio.h>
# include <stdlib.h>
# include <fcntl.h>
main(int argc, char *argv[])
{
int i,j;
char c;
FILE *fp;
if(argc < 2)
fprintf(stderr, "usage a.out <filename>\n");
fp = fopen(*++argv, O_RDONLY);
if(fp == NULL)
{
fprintf(stderr, "File cannot be opened\n");
exit(1);
}
else
{
while ((j = read(fp, &c, 1)) != 1)
{
// j = read(fp, &c, 1);
if(j <= 0)
break;
else
putchar(c);
}
fclose(fp);
}
}