Issue
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.
Solution
Your program isn't going to work very well - you're not providing enough arguments to read
and write
, for example (assuming you mean to be calling POSIX read(2)
and write(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:
./a.out FILE1 FILE2
replacing FILE1
with the name of your input file and FILE2
with the name of your output file.
Answered By - Carl Norum Answer Checked By - Senaida (WPSolving Volunteer)