Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.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中的结构类型未知_C_Pointers - Fatal编程技术网

在参数中使用结构类型数据时,参数函数C中的结构类型未知

在参数中使用结构类型数据时,参数函数C中的结构类型未知,c,pointers,C,Pointers,如何使用参数将struct类型数据传递给另一个函数?我已经创建了一个globalstruct,但我想我错过了一些东西 当我尝试上面的代码时,我得到了一个错误 未知类型名称“Stuff”(在我调用的第行myFunctionInsert(Stuff*Stuff)) 任何帮助都将不胜感激 谢谢您定义的类型是struct Stuff而不是Stuff。因此: // call another function int myFunctionInsert(struct Stuff *stuff); 或者使

如何使用参数将
struct
类型数据传递给另一个函数?我已经创建了一个
global
struct
,但我想我错过了一些东西

当我尝试上面的代码时,我得到了一个错误

未知类型名称“Stuff”(在我调用的第行
myFunctionInsert(Stuff*Stuff)

任何帮助都将不胜感激


谢谢

您定义的类型是
struct Stuff
而不是
Stuff
。因此:

// call another function
int myFunctionInsert(struct Stuff *stuff);
或者使用
typedef

typedef struct Stuff
{
    int id;
    String name[20];
} Stuff;

您定义的类型是
struct Stuff
而不是
Stuff
。因此:

// call another function
int myFunctionInsert(struct Stuff *stuff);
或者使用
typedef

typedef struct Stuff
{
    int id;
    String name[20];
} Stuff;

问题不仅在于缺少
typedef
。 另外,由于(x=0;x<25;x++)的
跨越了

struct Stuff *stuff[20];
另外
stuff[x].name='stuff';
不会飞行。您的意思是“stuff”。请注意,C语言中没有
String
类型

指定传递的结构数组大小的程序的工作版本可能如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

    typedef struct stuff
    {
        int id;
        char name[20];
    }Stuff;

    // call another function
    int myFunctionInsert(Stuff *stuff, int len);

    int myFunctionInsert(Stuff *stuff,int len)
    {
        int x;
        for(x = 0; x < len; x++){
            stuff[x].id = x;
            strcpy( stuff[x].name, "stuff");

            printf("stuff %i id=%d  name=%s\n", x, stuff[x].id, stuff[x].name );
        }
    }

    int main()
    {
        Stuff sf[25];
        myFunctionInsert(sf,5); // init 5 structures
        return 0;
    }

问题不仅在于缺少
typedef
。 另外,由于(x=0;x<25;x++)的
跨越了

struct Stuff *stuff[20];
另外
stuff[x].name='stuff';
不会飞行。您的意思是“stuff”。请注意,C语言中没有
String
类型

指定传递的结构数组大小的程序的工作版本可能如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

    typedef struct stuff
    {
        int id;
        char name[20];
    }Stuff;

    // call another function
    int myFunctionInsert(Stuff *stuff, int len);

    int myFunctionInsert(Stuff *stuff,int len)
    {
        int x;
        for(x = 0; x < len; x++){
            stuff[x].id = x;
            strcpy( stuff[x].name, "stuff");

            printf("stuff %i id=%d  name=%s\n", x, stuff[x].id, stuff[x].name );
        }
    }

    int main()
    {
        Stuff sf[25];
        myFunctionInsert(sf,5); // init 5 structures
        return 0;
    }