我看了其他帖子,说实话我仍然不确定是什么原因造成的问题。我编程在Visual Studio和错误C2059:语法错误:'字符串'
我有以下代码:(这是一个C主)
int main(int arc, char **argv) {
struct map mac_ip;
char line[MAX_LINE_LEN];
char *arp_cache = (char*) calloc(20, sizeof(char)); //yes i know the size is wrong - to be changed
char *mac_address = (char*) calloc(17, sizeof(char));
char *ip_address = (char*) calloc(15, sizeof(char));
arp_cache = exec("arp -a", arp_cache);
它使用以下CPP代码:
#include "arp_piping.h"
extern "C" char *exec(char* cmd, char* arp_cache, FILE* pipe) {
pipe = _popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL) {
strcat(arp_cache, buffer);
}
}
_pclose(pipe);
return arp_cache;
}
与匹配的头文件:
#ifndef ARP_PIPING_H
#define ARP_PIPING_H
#endif
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif
#include
#include
extern "C" char *exec(char* cmd, char* arp_cache, FILE* pipe);
#undef EXTERNC
但我一直得到以下错误:
1>d:\arp_proto\arp_proto\arp_piping.h(14): error C2059: syntax error : 'string'
1>main.c(22): warning C4013: 'exec' undefined; assuming extern returning int
1>main.c(22): warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
请问我能得到一些帮助,我已经看过关于C2059其他职位,但我仍然一事无成
2013-07-19
cxzp
+0
'#包括'@GrijeshChauhan我使用视觉工作室失踪 –
+0
,我们没有这样的头文件 –
+0
如果定义了'EXTERNC'宏C++,你为什么不使用它呢?此外,如果'#ifndef ARP_PIPING_H'应该是一个包含守护进程,'#endif'需要位于头部的末尾。现在,您可以防止“ARP_PIPING_H”的双重定义,但这不起任何作用 –