C
C
canabisss2018-10-26 07:33:21
C++ / C#
canabisss, 2018-10-26 07:33:21

How to assign a value to data in a C structure?

struct tableI  
{
  char name[4];
  float doctor[16];
  float bunk[16];
}с;

// нужно чтоб name - был масивом со строками, с данными  {РСФСР, Украина, Латвия, Эстония}. ДАнные менятся не будут, просто для хранения.

// а все остальные массивы с числами.

You need it in C, not C++.
Tell me how to organize it or what should be studied. I read articles on structures. didn't find anything.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eugene, 2018-10-26
@noobsa

Perhaps there is a solution here: https://learnc.info/c/structures.html

#include<stdio.h>

struct tableI  
{
    char *name[4];
    float doctor[16];
    float bunk[16];
} tableI;

int main()
{
    struct tableI a;
    a.name[0] = "РСФСР";
    a.name[1] = "Украина";
    a.name[2] = "Латвия";
    a.name[3] = "Эстония";
    // и т.д. ...
    printf("%s|%s|%s|%s", a.name[0],a.name[1],a.name[2],a.name[3]);
}

R
res2001, 2018-10-26
@res2001

What did you find so terrible in structures compared to ordinary arrays not in structures?

c.doctor[0] = 3.14;
c.doctor[15] = 6.28;
c.bank[5] = 0;
strcpy(& c.name[0], "Yes");

N
ns5d, 2018-10-26
@ns5d

https://linuxconfig.org/c-development-on-linux-str...

A
Andrey, 2018-10-27
@officialandrey

typedef struct NODE NODE;
typedef struct NODE* PNODE;
typedef struct DLIST DLIST;
typedef struct DLIST* PDLIST;

struct NODE {
  int key;
  int info;
  PNODE prev, next;
}node;

struct DLIST {
  int count, size;
  PNODE left, right;
}list;

int main () {
        nd->key = 1; // Ключ узла для поиска, удаления и т.п.
        nd->info = 1996; // Информация узла
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question