I want to scan a string and point a char
pointer to this scanned string.
int main(int argc, char *argv[]) {
char *string;
scanf("%s",&string);
printf("%s\n",string);
}
But gives a warning saying
warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char **'
How do I scan a string in a char *
without warnings.
Edit : It worked for the below code with warnings and I drilled down it to the above one so to be very specific.
int main(int argc, char *argv[]) {
int n = 2;
char *strings[2];
for(int i = 0; i < n; i++){
scanf("%s",&strings[i]);
printf("%s\n",&strings[i]);
}
}