Error C2059: syntax error : 'string'

c, c++, error-handling, visual-studio-2010

Solution

Change your `exec` declaration to use the `EXTERNC` macro you have taken pains to define.

EXTERNC char *exec(char* cmd, char* arp_cache, FILE* pipe);

Problem

I have looked at other posts and to be honest I am still not sure what is causing the problem. I am programming in Visual Studio and I have the following code: (this is a C main) ``` 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); ``` It uses the following cpp code: ``` #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; } ``` With the matching header file: ``` #ifndef ARP_PIPING_H #define ARP_PIPING_H #endif #ifdef __cplusplus #define EXTERNC extern "C" #else #define EXTERNC #endif #include <stdio.h> #include <string.h> extern "C" char *exec(char* cmd, char* arp_cache, FILE* pipe); #undef EXTERNC ``` But I keep on getting the following errors: ``` 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' ``` Please can I get some help, I have looked at other posts regarding the c2059 but am still getting nowhere

Original source

Related problems