使用全局变量,printf
不会返回有效值。
我尝试了这段代码没有成功:
struct test {
char *a;
char *b;
}
struct test test_main = {};
int modif_value(char *val) {
test_main.a = val;
}
int main () {
modif_value("1");
printf ("value after modif is %s \n", test_main.a);
return 0;
}
答案 0 :(得分:1)
#include <stdio.h>
struct test {
char *a;
char *b;
};
struct test test_main;
void modif_value(char *val) {
test_main.a = val;
}
int main () {
char c='1';
modif_value(&c);
printf ("value after modif is %s \n", test_main.a);
return 0;
}