Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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 在其他文件中共享文件中使用的typedef结构数组_C_Arrays_Typedef_Extern_Nrf51 - Fatal编程技术网

C 在其他文件中共享文件中使用的typedef结构数组

C 在其他文件中共享文件中使用的typedef结构数组,c,arrays,typedef,extern,nrf51,C,Arrays,Typedef,Extern,Nrf51,我无法在文件之间共享typef结构,具体地说是从一个文件和main.c共享。总而言之,我有以下几点: el array es true el array es true el array es true el array es true el array es true el array es true el array es false el array es false el array es false es true es true es true es true es true

我无法在文件之间共享typef结构,具体地说是从一个文件和main.c共享。总而言之,我有以下几点:

    el array es true
el array es true
el array es true
el array es true
el array es true
el array es true
el array es false
el array es false
el array es false
es true
es true
es true
es true
es true
es true
es false
es false
es false
帕戈斯h:

pagos.c:

我在这里使用trama_tpv和数组\u trama_tpv[TAMCOLAPAGOS],因为我通过使用一些函数用trama_tpv填充数组

主要条款c:

编辑: 解释如何填充阵列有点复杂,因为我在pagos.c中收集蓝牙帧。这是一段编译后用作nRF51蓝牙开发工具包固件的代码。问题是,我在pagos.c中获得信息,因为我可以使用自己的lib打印importusuario,以便在LCD-TFT显示器上打印。问题是,我需要获取数组的值,以便使用数组中存储的数据打印数组,并且我使用bool posicion_ocupada知道可以写入哪个数组位置。问题不在于代码的目标,而在于如何共享typedef数组结构,因为在Java中,在创建objetc时使用public就足够了,但在C中,我肯定遗漏了一些东西。 为了链接和编译,我使用Keil,这应该做得很好。无论如何,我也在尝试用XCODE编写一个单独的例子,结果是一样的,我可以分享bool,int。。。但不是结构数组:

typedef struct
{
    bool        posicion_ocupada;

}trama_tpv_t;
孤立示例: main.c:

#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "test.h"



int main(){


init();
change();


    for (int i=0; i<9; i++) {
        if(array_trama_tpv[i].posicion_ocupada)
            printf("\nel array es true");
        else
            printf("\nel array es false");
    }


printarray(); /*Used only because I though that maybe calling a function which is located into test.c it could be able to access the values I want from the array.*/

return(0);
       #include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "test.h"
//#include "global.h"


trama_tpv_t trama_tpv;
trama_tpv_t array_trama_tpv[9];


void init(void){
    for (int i=0; i<9; i++) {
        array_trama_tpv[i].posicion_ocupada=false;
    }



}

void change(void){
    for (int i=0; i<9; i++) {
        if (i<6) {
             array_trama_tpv[i].posicion_ocupada=true;
        }
        else{
        array_trama_tpv[i].posicion_ocupada=false;
    }

}
}

void printarray(void){
    for (int i=0; i<9; i++) {
        if (array_trama_tpv[i].posicion_ocupada) {
            printf("\nes true");
        }
        else
        {
           printf("\nes false");
        }
    }

}
    #ifndef __bittest__test__
#define __bittest__test__

#include <stdio.h>
#include <stdbool.h>
#include <time.h>


typedef struct
{
    bool        posicion_ocupada;

}trama_tpv_t;

extern trama_tpv_t array_trama_tpv[9];



void init(void);

void change(void);
void printarray(void);


#endif /* defined(__bittest__test__) */
问题是如果它应该是相同的数组,为什么我没有相同的结果。这可能吗?init()应该将所有布尔值设置为false,但它的行为不是这样的


我试着在函数中使用它。因此,我检查了设置一些断点,这些断点设置为array\u trama\u tpv[0]。posicion\u ocupada设置为true,但当我沿着数组打印数组的所有posicion\u ocupada值时,所有断点都为false。奇怪的是,我可以共享int、bool之类的变量,但是我不能共享这些值

先谢谢你。我已经检查并尝试了许多来自这里的帖子,如果我错过了什么,我很抱歉

问候,


Iván

请发布一个可验证的最小示例,因为不清楚您如何“使用一些函数填充阵列”,或者如何打印它。是否将pagos.h包含在main.c中?是否将编译器生成的两个模块链接到一个可执行文件中?您可能需要添加一个
printf(“pagos.c说array_trama_tpv位于%p\n”,array_trama_tpv)和main.c中的类似代码。我想我解决了这个问题。我添加了对我有用的代码和printf结果,因为也许有人会发现它很有用。谢谢大家,在我能够在我假装给出的最终解决方案中实现它之前,我不会关闭它。当做
       #include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "test.h"
//#include "global.h"


trama_tpv_t trama_tpv;
trama_tpv_t array_trama_tpv[9];


void init(void){
    for (int i=0; i<9; i++) {
        array_trama_tpv[i].posicion_ocupada=false;
    }



}

void change(void){
    for (int i=0; i<9; i++) {
        if (i<6) {
             array_trama_tpv[i].posicion_ocupada=true;
        }
        else{
        array_trama_tpv[i].posicion_ocupada=false;
    }

}
}

void printarray(void){
    for (int i=0; i<9; i++) {
        if (array_trama_tpv[i].posicion_ocupada) {
            printf("\nes true");
        }
        else
        {
           printf("\nes false");
        }
    }

}
    #ifndef __bittest__test__
#define __bittest__test__

#include <stdio.h>
#include <stdbool.h>
#include <time.h>


typedef struct
{
    bool        posicion_ocupada;

}trama_tpv_t;

extern trama_tpv_t array_trama_tpv[9];



void init(void);

void change(void);
void printarray(void);


#endif /* defined(__bittest__test__) */
    el array es true
el array es true
el array es true
el array es true
el array es true
el array es true
el array es false
el array es false
el array es false
es true
es true
es true
es true
es true
es true
es false
es false
es false