我想在整个项目中使用 Char *,我面临的问题如下。
我创建了一个头文件,如下所示:
文件.h
extern char *a;
文件1.c
#include "File.h"
char *a;
void foo()
{
//some manipulation on a
}
文件2.c
#include"File.h"
void foo1()
{
//using "a" here gives a garbage value
}
我确信 foo() 会在 foo1() 之前执行。
最佳答案
检查是否已使用 malloc() 为 char *a 分配了字节?如果没有,它肯定会打印垃圾值。分配后还 memset() 指针,以便初始化时没有任何垃圾
关于c - 在 C 项目中共享 "Char * ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29294180/