So I have this project where I need to open a file and print the contents in C, but I have to use unix system calls. However I'm not to clear as to why nothing prints. I try to run the code, but it seems to skip straight to the close error. I'm aware I need unistd.h, I already have that included.
#define MAXBUF 4096
int main(int argc, char* argv[]){
int x = 0, y, z = 1, a; //x: Counter, Y:int for open, z:another counter, a:int for read
char buff[MAXBUF]; //set buffer size
int fe,fn,ft; //fe = found E, fn = found n, ft = found T
if((y = open( argv[2], O_RDONLY )) == -1){
errHandler("Couldn't open ", argv[2]);
}
.
.
.
if(fn == 1){ //if fn returned true
printf("%d ", z++);
}
while( ( a = read( y, buff, MAXBUF ) ) > 0 ){
if ( buff == '\n' && fe && fn ) //<--
printf("$\n%4d: ", z++ );
else if ( buff == '\n' && fe )
printf("\n"); //Flags for various options
else if ( buff == '\t' && ft )
printf("^T");
else if ( buff == '\n' && fn )
printf("\n%4d: ", z++ ); //<--
else
printf("%c", buff);
}
close(y);
if ( close( y ) == -1)
printf("Unable to close file");
return 0;
}
edit: Here's the declarations. The '.' are skipping the code that's just setting the flags.