Reputation: 53
int main(int argc, char const *argv[])
{
char original[5] = ".txt";
int c;
strcat(argv[1], original);
FILE *find;
find = fopen( argv[1], "r");
if (find) {
while ((c = getc(find)) != EOF)
putchar(c);
fclose(find);
}
return(0);
}
What will I do? Now, i creating a project with c programming.
Upvotes: 3
Views: 4688
Reputation: 50774
strcat(argv[1], original);
The type of argv[1]
is const char*
, and the first argument of strcat
is char*
.
The strings in argv
are not supposed to be modified.
You basically need this (there is still room for improvement):
char txtextension[5] = ".txt";
char filename[200]; // 200 will be hopefully enough
strcpy(filename, argv[1]);
strcat(filename, txtextension);
FILE *find;
find = fopen(filename, "r");
Sidenotes:
char original[5] = ".txt";
with char original[] = ".txt";
. In the latter case the compiler automatically allocates the correct memory size.original
should be named for example txtextension
.Upvotes: 2