#include <stdio.h>
#include <stdlib.h>
void SetInteger();
int main(void)
{
SetInteger();
}
void SetInteger()
{
unsigned char *ptr;
scanf("%s", ptr);
printf("%s", ptr);
}
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned char *ptr;
scanf("%s", ptr);
printf("%s", ptr);
}
In the same case above, the function receives input but does not output the input value, but in the case below, if it is done directly from the main, it outputs the input value. I want to know what the difference is.
c
char *
cannot accept a string as a scanf()
function. To receive a string, you can use the malloc()
function to allocate memory. Alternatively, you can declare it as an array of char[]
to allocate memory in advance and receive a string.
https://dojang.io/mod/page/view.php?id=337, please refer to it.
© 2024 OneMinuteCode. All rights reserved.