I am new in C program and linux, how can we compile and run this program?
I have tried gcc example.c then ./a.out but it gives an error like input file cannot be opened ( I have written this error in the read method)
// example.c
int main(int argc, char *argv[])
{
char* input = argv[1];
read(input);
char* output = argv[2];
write(output);
return 0;
}
Thanks.
Your program isn’t going to work very well – you’re not providing enough arguments to
readandwrite, for example (assuming you mean to be calling POSIXread(2)andwrite(2), that is).To answer your actual question, the problem appears to be that you’re not providing any arguments. You need to run it something like:
replacing
FILE1with the name of your input file andFILE2with the name of your output file.