Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想从我的C程序中调用一个外部COBOL-IT函数。获取错误“;错误265:&x27;productid';:未声明的标识符_C_Cobol_Arrays - Fatal编程技术网

我想从我的C程序中调用一个外部COBOL-IT函数。获取错误“;错误265:&x27;productid';:未声明的标识符

我想从我的C程序中调用一个外部COBOL-IT函数。获取错误“;错误265:&x27;productid';:未声明的标识符,c,cobol,arrays,C,Cobol,Arrays,所以我有一个外部COBOL-IT函数,我想从我的C程序中调用它。目前,我不断收到错误“ERRORC2065:'productid”:未声明的标识符。“aantal”也是如此。我的C有点生锈,因为我已经有一段时间没有使用它了,所以如果有人能帮我,那就太好了。如果我去掉“&”,它也不会工作 #include <stdio.h> #include "libcob.h" //#pragma linkage (verkoop, COBOL) extern void verkoop(char

所以我有一个外部COBOL-IT函数,我想从我的C程序中调用它。目前,我不断收到错误“ERRORC2065:'productid”:未声明的标识符。“aantal”也是如此。我的C有点生锈,因为我已经有一段时间没有使用它了,所以如果有人能帮我,那就太好了。如果我去掉“&”,它也不会工作

#include <stdio.h>
#include "libcob.h"
//#pragma linkage (verkoop, COBOL)

extern void verkoop(char *productid, char aantal*);

int main(int argc, char *argv[])
{
    COB_RTD = cob_get_rtd();
    cob_init(rtd, 0, NULL);
    char productid[6] = "000020";
    char aantal[6] = "000200";
    printf("Hello world");  
    verkoop(&productid, &aantal);
    return 0;
}

更新:我通过在代码的第一行声明productid和aantal解决了这个问题。

您一定有其他编译错误。productid和aantal的声明不正确

char productid[6] = "000020";
char aantal[6]    = "000200";
用VC++编译时显示错误C2117:“productid”:数组边界溢出

它们是短的一个字节,用于字符串文本中的空终止。为什么不这样做呢:

char *productid = "000020";
char *aantal = "000200";

您必须有其他编译错误。您对productid和aantal的声明不正确

char productid[6] = "000020";
char aantal[6]    = "000200";
用VC++编译时显示错误C2117:“productid”:数组边界溢出

它们是短的一个字节,用于字符串文本中的空终止。为什么不这样做呢:

char *productid = "000020";
char *aantal = "000200";
1) 常量字符数组太小,无法容纳以null结尾的初始字符串的值

2) 同样,您对函数的声明是不正确的

extern void verkoop(char*productid,char aantal*);

应该是

extern void verkoop(char*productid,char*aantal);

(提示:请看“*”中的aantal)

3) 您使用无效参数调用函数。函数调用应已被删除

verkoop(productid,aantal);

您可以分享有关您正在使用的编译器的更多信息吗?

1)您的常量字符数组太小,无法容纳以null结尾的初始字符串的值

2) 同样,您对函数的声明是不正确的

extern void verkoop(char*productid,char aantal*);

应该是

extern void verkoop(char*productid,char*aantal);

(提示:请看“*”中的aantal)

3) 您使用无效参数调用函数。函数调用应已被删除

verkoop(productid,aantal);


您能分享更多关于您正在使用的编译器的信息吗?

以下是入门手册中的示例C程序:

/* hello.c */
#include <libcob.h>
extern int say(char *hello, char *world);
int main()
{
COB_RTD = cob_get_rtd();
int ret;
int return_status;
char hello[7] = "Hello ";
char world[7] = "World!";
cob_init(rtd, 0, NULL);
ret = say(hello, world);
cob_stop_run (rtd, return_status);
return ret;
}
/*hello.c*/
#包括
extern int say(char*你好,char*世界);
int main()
{
COB_RTD=COB_get_RTD();
int ret;
int返回_状态;
char hello[7]=“hello”;
char world[7]=“world!”;
cob_init(rtd,0,NULL);
ret=说(你好,世界);
cob\u停止\u运行(rtd,返回\u状态);
返回ret;
}
这显示了从C运行COBOL-ITAPI的简单方法

请注意,COBOL没有“字符串”。COBOL中的六字节字段占用六个字节,并且不会以“null”或其他任何字符终止


“通过引用”传递给COBOL程序的数据可以在COBOL程序中进行修改。如果不应该修改,则由程序员来确定是否正确。

以下是入门手册中的示例C程序:

/* hello.c */
#include <libcob.h>
extern int say(char *hello, char *world);
int main()
{
COB_RTD = cob_get_rtd();
int ret;
int return_status;
char hello[7] = "Hello ";
char world[7] = "World!";
cob_init(rtd, 0, NULL);
ret = say(hello, world);
cob_stop_run (rtd, return_status);
return ret;
}
/*hello.c*/
#包括
extern int say(char*你好,char*世界);
int main()
{
COB_RTD=COB_get_RTD();
int ret;
int返回_状态;
char hello[7]=“hello”;
char world[7]=“world!”;
cob_init(rtd,0,NULL);
ret=说(你好,世界);
cob\u停止\u运行(rtd,返回\u状态);
返回ret;
}
这显示了从C运行COBOL-ITAPI的简单方法

请注意,COBOL没有“字符串”。COBOL中的六字节字段占用六个字节,并且不会以“null”或其他任何字符终止


“通过引用”传递给COBOL程序的数据可以在COBOL程序中修改。如果不应该修改,则由程序员来确保它不会被修改。

请显示verkoop()的声明。这是唯一的两个错误,因为这很奇怪。此外,您不需要&“运算符,如果输入参数签名只是一个指针。您的extern声明是错误的。现在您已经将COBOL程序作为一个独立的程序运行,我假设您将重新将其集成到这个函数中。”。我认为您应该首先使用文档化的API,因为这是您课程的预期内容。我认为,使用pragma也应该可以,但这是一种“非标准”的方法,如果你只是使用它,你可能会失去标记(也许你会获得额外的积分?)C-Cobol链接现在工作得很好,下一步是使用套接字建立连接,在一个c程序和一个java程序之间,以便稍后从我的java程序发送输入。我希望我有时间实施这两种方法,不幸的是,在我完成这项任务的时间里,我已经有太多的工作要做:(如果只有时间以一种方式进行,请使用API,Robin,使用API。向Obi Wan道歉,但是使用文档记录的内容,您会遇到更少的问题,并且您可以自己解决更多问题。请显示verkoop()的声明。这是唯一的两个错误,因为这很奇怪。此外,您不需要“&”运算符,如果输入参数签名只是一个指针。您的extern声明是错误的。既然您有独立的COBOL程序,我假设您将重新将其集成到此中。我认为您应该首先使用文档化的API,因为这是您课程的预期内容。我认为使用pragma也应该有效,但这将是一种“非标准”的方式,如果你只是使用这种方式,你可能会失去分数(也许你会获得额外的学分?)C-Cobol链接现在运行良好,下一步是使用套接字在C程序和java程序之间建立连接,以便稍后从我的java程序发送输入。我希望我有时间实现这两种方法,不幸的是,在我必须完成此任务的时间内,我已经有太多的工作要做:(如果只有时间用一种方法,那就用API,罗宾,用API。向欧比道歉