Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Regarding the output problem of scanf, some experts can ask me how to use scanf to output multiple types of variables. Here is an example I wrote.
Regarding the output problem of scanf, some experts can ask me how to use scanf to output multiple types of variables. Here is an example I wrote.

The main reason is that the memory pointed to by your pointer b is not determined, so an error will occur. You have just declared a character pointer, but where it points is not determined. This is the famous dangling pointer problem.

To apply for a memory before input, you can use functions such as malloc to apply dynamically, or you can directly apply for a character array to store the input string. Then let b point to this character array, and that's it.

#include

int main()

{int a;char *b;

char name [ 20];

b=name;

scanf("%d%s",&a,b); //It is best not to add commas and separate them directly with spaces when entering That’s it

printf("%d,%s\n",a,b);

return 0;

}