如何从C中的函数返回字符串

时间:2017-11-25 16:49:31

标签: c

Tnil

如何将变量name_to_main的值返回到指针* p_name?

1 个答案:

答案 0 :(得分:0)

#include <stdio.h>
#include <stdlib.h>
char*pointer(char*now);

void main() {
    char*name = "Paz Leviim", **p_name = &name;
    *p_name = pointer(*p_name);
    printf("Now it's %s", *p_name);
    getchar();
}
char*pointer(char*now) {
    static char name_to_main[100];
    printf("The value now is %s\nPlease set value:",now);
    scanf_s("%[^\n]%*c", &name_to_main,100);
    return name_to_main;
}

现在全部工作:)