标签: structure

运行结构并打印所有值?

我有一个指向结构的指针,我想通过反复试验获取所有成员.我试图通过将指针递增1并对其进行解除来完成结构.它应该从结构中返回一个正确的值(每次i*sizeof(int)),但它不会.

我究竟做错了什么?

fn (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
{

    /*
     assume that all struct members are int types

     typedef    struct 
     {
     mach_msg_bits_t    msgh_bits;
     mach_msg_size_t    msgh_size;
     mach_port_t        msgh_remote_port;
     mach_port_t        msgh_local_port;
     mach_msg_size_t    msgh_reserved;
     mach_msg_id_t      msgh_id;
     } mach_msg_header_t;

     size of the struct is 24.
     */

    printf("ID: %d \n",InHeadP->msgh_id); //prints 'ID: 1337'
    printf("Ptr: %p\n",InHeadP);

    for (int i = 0; i <= 24; i++)
    {
        int deref = *((int*)(InHeadP+i));
        printf("InHeadP[%d]=%d\n",i,deref);
            //no sign of 1337 anywhere

    }
}
Run Code Online (Sandbox Code Playgroud)

PS我知道我不应该这样做,但这仅用于测试目的.

c struct structure

1
推荐指数
1
解决办法
1万
查看次数

C中的结构填充

如果我在以下C中有结构定义

typedef struct example 
{
  char c;
  int ii;
  int iii;
};
Run Code Online (Sandbox Code Playgroud)

当我声明上述结构类型的变量时,应分配的内存是多少.例如ee;

什么是结构填充以及是否存在与结构填充相关的风险?

c structure

1
推荐指数
1
解决办法
1533
查看次数

内部Clear()方法的C#结构

我想简单地建立商店信息的结构.我的问题是创建清除存储值的内部方法.

   public struct GraphValues
   {
        public int min, max, ...;

        public GraphValues(int min, int max, ...)
        {
            this.min = min;
            this.max = max;
            ...
        }

        public static void Clear(this GraphValues values)
        {
            values.min.Equals(null);
            values.max.Equals(null);
            ...
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以在这个结构中写新值就行了,

GraphValues val = new GraphValues()
val.max = 12;
val.min = 1;
Run Code Online (Sandbox Code Playgroud)

但我想将所有结构都设置为null.打电话给像

val.Clear();
Run Code Online (Sandbox Code Playgroud)

任何的想法?Thnaks

c# methods structure internal clear

1
推荐指数
1
解决办法
2769
查看次数

指向C中结构的指针

typedef struct stack{
 int size;
 int array[30];
}STACK;

int p;
STACK *W;
Run Code Online (Sandbox Code Playgroud)

(*W).array和之间有什么区别 (*W).array[0]
如果我有Wp?如何获得指向数组中第一个元素的int指针?

c pointers structure

1
推荐指数
1
解决办法
179
查看次数

发布时需要哪些Blackberry App World提交文件

真的很抱歉要问一些偏离主题的问题,但我们有一个Blackberry 5.0应用程序,我们需要尽快在应用程序商店中起床.

我有一个包含以下内容的zip文件

[根文件夹] .alx [子文件夹<5.0.0>] .cod .csi .cso .debug .jad .jar [/子文件夹] [/根文件夹]

任何人都知道这是否可以按原样提交,或者我不确定这是否是预先调试版本,并且需要重新编译才能发布(iOS版).我注意到它不包含release.xml文件或devices.txt,我也觉得应该将子文件夹重命名为"Appname_5.0.0"

blackberry structure submission appworld

1
推荐指数
1
解决办法
1240
查看次数

将数组复制到结构中

我有一个9字节的数组,我想将这些字节复制到一个结构:

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

typedef struct _structure {
    char one[5];        /* 5 bytes */
    unsigned int two;   /* 4 bytes */
} structure;

int main(int argc, char **argv) {

    structure my_structure;

    char array[]    = {
        0x41, 0x42, 0x43, 0x44, 0x00,   /* ABCD\0 */
        0x00, 0xbc, 0x61, 0x4e          /* 12345678 (base 10) */
    };

    memcpy(&my_structure, array, sizeof(my_structure));

    printf("%s\n", my_structure.one);   /* OK, "ABCD" */
    printf("%d\n", my_structure.two);   /* it prints 1128415566 */

    return(0);
}
Run Code Online (Sandbox Code Playgroud)

该结构的第一元件my_structure,one被正确地复制; 但是,my_structure.two包含1128415566,而我期望12345678. array …

c memory arrays structure copying

1
推荐指数
1
解决办法
1万
查看次数

在C中分配内存并生成结构

我正在尝试通过Kernighan的书"C编程语言"来教我自己C为今年春天的数据结构类做准备(C是必需的先决条件),但我仍然坚持如何处理多个结构以及如何存储倍数以便稍后用于计算和输出.我为与学生记录相关的结构编写了一些代码,其中包含id和分数的变量.函数名称和参数必须保持原样,注释描述每个函数应该执行的操作.

所以这就是我尝试过的.我想在分配函数中为十个学生设置一个结构数组,如下所示:

struct student s[10];
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将其返回到main然后将其传递给generate函数时,我会遇到不兼容错误.我目前的努力如下.但是,正如您所看到的,我的代码无法存储除最后一组记录(即student.id和student.score)之外的任何内容.很明显,我错过了一个关键组件,这使我无法生成随机的唯一学生ID,因为我无法检查新的ID与之前的ID.我也无法继续编写函数来计算学生成绩.任何建议,将不胜感激.提前致谢.

#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#include<assert.h>

struct student{
int id;
int score;
};

struct student* allocate(){
     /*Allocate memory for ten students*/
    struct student* s = malloc(10 * sizeof(struct student));
    assert (s != 0);

     /*return the pointer*/
     return s;
}

void generate(struct student* students){
 /*Generate random ID and scores for ten students, ID being between 1 and 10, scores between 0   and 100*/
   int i;
   for (i = 0; i < 10; i++) {
       students …
Run Code Online (Sandbox Code Playgroud)

c memory-management structure

1
推荐指数
1
解决办法
1427
查看次数

在MySQL数据库中为一个orderid添加多个项目

我试图在orderid我的数据库中插入多个项目,我不知道如何做到这一点.

我当前的db表结构:

order
orderid (auto increment)
productdesc
quantity
Run Code Online (Sandbox Code Playgroud)

数据库中的当前结果(从datagrid添加项目时)

orderid   productdesc   quantity  
1         test          1          
2         value         2
3         demo          3
Run Code Online (Sandbox Code Playgroud)

期望的结果

orderid productdesc quantity
1       test        1  
1       value       2
1       demo        3
Run Code Online (Sandbox Code Playgroud)

有没有办法orderid在下一个订单到来之前为一个添加多个项目,这意味着orderid它将是2.有人能指出我正确的方向吗?谢谢

mysql database structure

1
推荐指数
1
解决办法
2624
查看次数

如何快速填充结构值?

我使用Visual Studio 2013与标准C.

我的程序需要四行才能 {"Analysis 1", "AN 1", 0, 0.0667}输入Fach[0].

我不想浪费这么多行来填充这个数组.

有没有更好的方法将这四行合二为一?

#define _CRT_SECURE_NO_WARNINGS
#include "header.h"
#include <stdio.h>
#include <string.h>

struct sFach
{
    char Mod[40];       //Modulbezeichnung
    char Ab[5];         //Abkürtzung
    int Note;           //Note
    double Gew;         //Gewichtungsfaktor
};

int main()
{
    struct sFach Fach[31];

    strcpy(Fach[0].Mod, "Analysis 1");
    strcpy(Fach[0].Ab, "AN 1");
    Fach[0].Note = 0;
    Fach[0].Gew = 0.0667;

    strcpy(Fach[1].Mod, "Algebra");
    strcpy(Fach[1].Ab, "AL");
    Fach[1].Note = 0;
    Fach[1].Gew = 0.0889;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c arrays structure

1
推荐指数
2
解决办法
7296
查看次数

C++结构中数组的初始化

我想在构造对象时在结构中启动数组的大小:

class someclass{
public:
  someclass(int init_msgsz) { this->msgsz = init_msgsz; }

private:
   int msgsz;
   struct msgbuf {
      long msqtype;
      uint8_t msgtext[msgsz];
   } send_message_buf, receive_message_buf;
};
Run Code Online (Sandbox Code Playgroud)

但有些事情是错的:-(任何人都帮帮我?
注意这个结构来自:msgrcv,msgsnd - 消息操作

更新:

#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdint.h> //uint8_t == unsigned char
#include <string.h>

class communication
{
public:
    communication(key_t &init_key, int &init_msgflg, size_t init_msgsz);
    ~communication();

    int send_msg(uint8_t *send_msg);
    int receive_msg(uint8_t *rec_msg);

private:
    int msqid;
    key_t key;
    int msgflg;
    int msgsz;
    size_t buf_length;

    struct msgbuf {
        long    msqtype; …
Run Code Online (Sandbox Code Playgroud)

c++ structure

1
推荐指数
1
解决办法
119
查看次数