我有一个简单的C程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argCount, string args[])
{
// ....
}
我的make文件是:
TARGET = test
all: $(TARGET)
$(TARGET): $(TARGET).c
cc -g -std=gnu99 -o $(TARGET).out $(TARGET).c -lm
它会出现编译错误:未知类型名称&#39;字符串&#39;在main的args参数。
还必须包含哪些才能使用字符串?
答案 0 :(得分:2)
c中没有名为string
的类型。 C语言使用以null结尾的字符数组作为字符串。整个string.h也是如此。
查看任何函数定义,例如:strlen - size_t strlen( const char *str );
。
我猜你可以使用typedef
来代替typedef char* string;
,但我会反对它。在我看来,这会引起太多混乱。
所以你的代码应该是这样的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argCount, const char* args[])
{
// ....
return 0; // don't forget it other wise your app will spit some random exit code
}
答案 1 :(得分:0)
c中没有名为字符串的类型。 如果是从学校来的,则可能在头文件中的“字符串”某处已经包含typedef:
#define MAX_CHAR 100
typedef char string[MAX_CHAR+1];