标签: structure

为什么我收到"没有效果的声明"警告?

以下是我的代码

/* Initialise default without options input. */
options -> processHiddens = false;
options -> timeResolution = DEFAULT_MOD_TIMES;
options -> performSync = true;
options -> recursive = false;
options -> print = false;
options -> updateStatus = true;
options -> verbose = false;
options -> programname = malloc(BUFSIZ);
options -> programname = argv[0];

while ((opt = getopt(argc, argv, OPTLIST)) != -1)
{
    switch (opt)
    {
        case 'a':
            !(options -> processHiddens);
        case 'm':
            options -> timeResolution = atoi(optarg);
        case 'n':
            !(options …
Run Code Online (Sandbox Code Playgroud)

c structure compiler-warnings

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

C中的进程结构内存分配

编辑:

Typedef struct SPro{
     int arrivalTime;
     char processName[15];
     int burst;
} PRO;
Run Code Online (Sandbox Code Playgroud)

我有一个PRO类型的数组

PRO Array[100];
PRO enteringProcess;
//initialize entering process
Run Code Online (Sandbox Code Playgroud)

然后我需要创建一个新进程并使用malloc为该进程分配内存然后将指针从数组指向malloc返回的内存块.

PRO *newPro = (PRO *) malloc (sizeof(PRO));
newPro = enteringProcess;
ProArray[0] = *newPro;
Run Code Online (Sandbox Code Playgroud)

由于程序在运行时崩溃,我似乎做错了.有帮助吗?谢谢!

c arrays malloc structure

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

C - 如何找到结构的大小?

在c中,假设你有以下结构和一个实例:

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

int main()
{
    typedef struct _a {
        int *a1;
        float *a2;
        char *a3;
    }a;

    a b;
    b.a1 = (int *) malloc(sizeof(int) * 10);
    b.a2 = (float *) malloc(sizeof(float) * 10);
    b.a3 = (char *) malloc(sizeof(char) * 10);

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

现在,如何找到分配/与变量b关联的总内存?sizeof(b)将返回结构中指针的组合大小,但不会计算使用malloc为不同类型/大小分配的内存总和.如何在内存中找到此结构的总大小(包括填充,如果适用)?

c memory pointers structure sizeof

0
推荐指数
2
解决办法
1924
查看次数

无法在C++中定义结构数组

ball用这种方式定义了结构:

struct ball
{
 _vector coordinates;
 _vector velocity;
 _vector acceleration;

 int border;
 int color;
 int radius;

 float mass;

 void step();
 void clear();
 void render();
};
Run Code Online (Sandbox Code Playgroud)

(数据类型_vector在之前定义,它代表数学中的向量)

在main函数中我想定义一个balls 数组,所以我写了这段代码:

int main(int argc, char** argv)
{
    struct ball balls[NO_BALLS];
.
.
.
}
Run Code Online (Sandbox Code Playgroud)

但是当我想编译代码时,我得到了这个错误:

调用`ball :: ball()'候选人没有匹配函数:ball :: ball(const ball&)

c++ arrays structure

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

结构和功能(通过引用传递)

请指导我这个代码,我想使用数组和函数存储5个数据的列表,这是我的一段代码,但这给了我一个错误("33"):

Cannot convert `ABC (*)[5]' to `ABC*' for argument `1' to `void pass(ABC*)' 
Run Code Online (Sandbox Code Playgroud)

码:

#include <iostream>

using namespace std;

struct ABC{
   char name[20];
   int phone;
   char address[20];


   };

   void pass(ABC *abc){

  for(int i=0; i<5;i++){
        cout<<"Enter name"<<endl;
        cin>>abc[i].name;

        cout<<"Enter phone"<<endl;
        cin>>abc[i].phone;

        cout<<"Enter address"<<endl;
        cin>>abc[i].address;           

        }

 }

 int main()
 {
ABC abc[5];

   pass(&abc);    

system("PAUSE");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers structure function

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

为什么scanf不接受这个C结构的元素?

我是C的新手,正在研究结构.我创建了一个简单的结构,并尝试通过scanf()结构变量输入输入值,但我只获得部分/垃圾输出.我在这里错过了什么吗?

这是我的原始代码 -

#include<stdio.h>
void main()
{
    struct book
    {
        char name;
        float price;
        int pages;
    };

    struct book b1,b2,b3;
    int i;
    printf("\n Enter the names, prices and no. of pages of the 3 books: \n");
    scanf("%c %f %d", &b1.name,&b1.price, &b1.pages);
    scanf("%c %f %d", &b2.name,&b2.price, &b2.pages);
    scanf("%c %f %d", &b3.name,&b3.price, &b3.pages);   

    printf("\n You have entered: \n");
    printf("%c %.2f %d", b1.name,b1.price, b1.pages);
    printf("%c %.2f %d", b2.name,b2.price, b2.pages);
    printf("%c %.2f %d", b3.name,b3.price, b3.pages);
}
Run Code Online (Sandbox Code Playgroud)

这是一组输出 -

Enter names, prices & …
Run Code Online (Sandbox Code Playgroud)

c struct structure scanf

0
推荐指数
2
解决办法
1149
查看次数

将元素添加到链表(C)

我想创建一个链接列表,我可以在以后添加更多元素,但我对当前代码的问题是所有以前的元素被最后添加的元素覆盖.这是我的代码:

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

struct node {
    char *name;
    struct node *next;
}*head;



void add( char *str ) {
    struct node *temp;
    temp=(struct node *)malloc(sizeof(struct node));
    temp->name=str;

    if (head== NULL) {
        head=temp;
        head->next=NULL;

    } else {
        temp->next=head;
        head=temp;
    }
}

void  display(struct node *r) {
    r=head;
    if(r==NULL)
        return;

    while(r!=NULL) {
        printf("%s ",r->name);
        r=r->next;
    }

    printf("\n");
}

int  main()
{
    char *str;
    struct node *n;
    head=NULL;
    while(scanf("%s",str) == 1) {
        add(str);
        display(n);
    }

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

c structure linked-list

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

我称这个功能错了吗?

我正在编写一个程序来计算两次给定时间之间的经过时间.

由于某种原因,我收到错误:在我的main函数之前我的elapsedTime函数原型的预期标识符或'C'.

我试过在程序中移动它,如果在声明了t1和t2之后找到它,它就没有区别.有什么问题?

谢谢

#include <stdio.h>

struct time
{
  int seconds;
  int minutes;
  int hours;
};

struct elapsedTime(struct time t1, struct time t2);

int main(void)
{

    struct time t1, t2;

    printf("Enter start time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d:%d:%d", &t1.hours, &t1.minutes, &t1.seconds);

    printf("Enter stop time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d:%d:%d", &t2.hours, &t2.minutes, &t2.seconds);

    elapsedTime(t1, t2);

    printf("\nTIME DIFFERENCE: %d:%d:%d -> ", t1.hours, t1.minutes, t1.seconds);
    printf("%d:%d:%d ", t2.hours, t2.minutes, t2.seconds);
    printf("= %d:%d:%d\n", differ.hours, differ.minutes, differ.seconds); …
Run Code Online (Sandbox Code Playgroud)

c structure function

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

如何为golang中的结构片赋值

我正在使用表驱动测试我的方法,但在将值分配给结构数组的字段时出错,情况如下所示.

var validStats = []struct{
    status       []v1.ReplicaStatus
}{
   {
     status: []v1.ReplicaStatus {
             IP              string
             Status          string
             DataUpdateIndex string
    }{
       {
           IP:              "10.10.10.10",
           Status:          "Online",
           DataUpdateIndex: "1",
       },
       {
           IP:              "10.10.10.11",
           Status:          "Online",
           DataUpdateIndex: "1",
       },
     },
   }
}
Run Code Online (Sandbox Code Playgroud)

missing ',' in composite literal在第6行和代码末尾收到错误.这有什么问题?

structure go

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

C中的结构.未知的类型名称,

我是C语言中的新结构,但据我所知,我的代码是"正确的".我正在使用Codeblocks,但我也在DEV C++中编译它,我得到了同样的错误

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

struct film{
   int year;
   char  title[30];
   char  director[30];
   char  main_char[30];
} ;


int main ()
{

    film venom={ 2018, "Venom", "Ruben Fleischer", "Tom Hardy" };

    printf("Year: %d\n", venom.year);
    printf("Title: %s\n", venom.title);
    printf("Director: %s\n", venom.director);
    printf("Main Character: %s\n", venom.main_char);

    system("PAUSE");
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

我不知道有什么错误. 在此输入图像描述

c structure codeblocks

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