I have this homework to do in C. I'm beginner so it is probably very easy, but anyway I have a problem with it.
int main(int argc, char* argv){
int fd=open(argv[1], O_RDONLY);
int fileLength=(int)lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
char buf[fileLength];
read(fd,buf,fileLength);
int i=0;
for(i=0; i<fileLength; i++){
printf("%c",buf[i]);
}
printf("\n");
}
I get this error:
warning: passing argument 1 of ‘open’ makes pointer from integer without a cast
If I write "file"
instead of argv[1]
, everything is ok.
int main(int argc, char* argv){
has to be:
int main(int argc, char *argv[])
See the error?