int main(int argc, char* argv[]) {
char file1 = argv[1];
char file2 = argv[2];
}
I am getting an error message here - initialization makes integer from pointer without a cast. file1 and file2 are the names of files. How can I approach to this?
argv[1]
and argv[2]
have the type char *
that point to strings while objects file1
and file2
have the type char and are not pointers. So the compiler issues an error that you are trying to assign pointers (argv[1]
and argv[2]
) to characters (file1
and file2
) that does not make a sense..
char file1 = argv[1];
char file2 = argv[2];
You need to write
char *file1 = argv[1];
char *file2 = argv[2];
In this case the pointers file1
and file2
will point to the user supplied strings that denote file names.