30 lines
479 B
C
30 lines
479 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
char *create_char_arr(int n)
|
||
|
{
|
||
|
char *p = (char *)malloc(n * sizeof(char));
|
||
|
if (NULL == p)
|
||
|
{
|
||
|
perror("malloc error");
|
||
|
return NULL;
|
||
|
}
|
||
|
perror("malloc success");
|
||
|
return p;
|
||
|
}
|
||
|
|
||
|
void input_name(char **q)
|
||
|
{
|
||
|
printf("输入数据: ");
|
||
|
scanf("%s", *q);
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
char *p = NULL;
|
||
|
p = create_char_arr(20);
|
||
|
input_name(&p);
|
||
|
printf("输出数据: %s\n", p);
|
||
|
free(p);
|
||
|
return 0;
|
||
|
}
|