c How to input values from the keyboard to assign struct variables

Updated on number 2024-02-09
19 answers
  1. Anonymous users2024-02-06

    First, define the struct and assign values to the elements in the struct in turn

    Reference**. #include

    typedef struct stu{ define struct type int a; }

    int b;

    int c;

    int main()

    stu s;Define the struct.

    Enter each element in turn.

    printf("The struct elements are: %d %d %d",,, Output each element.

    return 0;

    Result: The struct elements are: 1 2 3

  2. Anonymous users2024-02-05

    It's simple: first you have to have a structure name

    struct stud

    If it's an array, you can write it like this:

    struct stud, got it? If you don't understand anything, contact again!

  3. Anonymous users2024-02-04

    To assign a value to a struct, define the struct first, and then assign values to the struct members individually, you can use the scanf() function, for example:

    #include

    struct student

    void main()

    Screenshot of the run:

  4. Anonymous users2024-02-03

    Forehead! If you define a struct variable ren, you need to assign a value to its members. --scanf("%s",&;

  5. Anonymous users2024-02-02

    It's very simple: in this example, I suggest you use getsgets(ren[0].) instead of scanfgonghao) is OK because they are all character arrays

  6. Anonymous users2024-02-01

    The simplest one is a student number and a name.

    For example, include

    struct stu

    int main()

    If you need other elements, add them as well.

  7. Anonymous users2024-01-31

    To give you a small example:

    #include

    struct stu

    main()Satisfied!

  8. Anonymous users2024-01-30

    If it's an array of structs, it's fine, otherwise you'll have to useOperators operate one by one.

  9. Anonymous users2024-01-29

    Define an array of structures.

    For example, stuct temp;

    The keyboard enters the value to the array.

    scanf("d%",scanf("d%",

  10. Anonymous users2024-01-28

    How do you want to initialize it?

    struct node

    struct node a,*b;

    b=a;Clean.

    memset(b, 0, sizeof(struct node));

    Assignment.; strcpy(, "12345");

    b->a=0;

    strcpy(b->b, "12345");

  11. Anonymous users2024-01-27

    c can't be assigned like this, this way can only be initialized at the time of definition.

    If int a[2] = is correct, but defining an array and then a= is incorrect, you should assign values one by one. In addition, when you define it, you need to request memory for variables, and the compiler will assign the value of your initial words to memory, but if you use it as a pointer when you assign a value later, the syntax will be incorrect.

    m1->edges=,}

    You can define the array you want to start with a const array, and then use for to assign the value, there is no other way,};

  12. Anonymous users2024-01-26

    with member symbols. Pander to.

    Like what. struct date

    struct student

    student1;

    So if you want to assign the year value to student1's birthday.;

  13. Anonymous users2024-01-25

    typedef struct _book_infobookinfo;

    The values are assigned: bookinfo bookinfo;

    If you're satisfied, please give me some points, I'm seriously short of points. Hehe.

  14. Anonymous users2024-01-24

    Struct assignment should not be done to all items in the struct, for example:

    struct node

    node s1,s2;

    If the value of s2 is paid to s1, then:

    s1->data=s2->data;

    s1->next=s2->next;

    This is called struct assignment.

    Each part has to be assigned.

  15. Anonymous users2024-01-23

    Direct assignment, no different from other members.

  16. Anonymous users2024-01-22

    For struct variables, you can assign values directly like you do: s1 =s2, and the pointer to structs is represented like this.

    struct structa *s1;

    Still have questions, please ask.

  17. Anonymous users2024-01-21

    str *st;This is to define a pointer, but without allocating a specific memory space to the pointer.

    st).age= 1;Employing * on a pointer that does not specify a memory space will cause the program to "get confused" and quit abnormally!

    str st1;What is defined here is a struct variable that has its own storage space.

    1;This is normal struct element assignment! Normal, of course.

  18. Anonymous users2024-01-20

    *st is the pointer to be assigned and should be used.

    The latter is just a normal variable, which is to get the value of a property in the struct.

  19. Anonymous users2024-01-19

    #include ""

    #include ""

    #define n 30

    struct date defines a struct date that contains 3 members.

    struct student defines a struct student num1;

    main()

    mem1=,mem2=;

    struct student num1=,"Ankang City, Shaanxi Province",100};The error that appears is: syntax error:',"Shaanxi Province Labor City",100};The error that appears is:

    syntax error:'

    Changed the compilation through.

Related questions
24 answers2024-02-09

The easiest way to do this is to create a constructor with a string parameter in form2, and then generate a form2 form. >>>More

18 answers2024-02-09

Buy a witch doctor in the store and plug in the eyes and kill Xiao Xiaoqiang! Xiaoqiang is not fierce, but the fierce is Xiaoxiaoqiang's super BT after attackingBut Xiao Xiaoqiang's blood is pitiful, and he will die if he uses a magic trick if he stands far away. >>>More

8 answers2024-02-09

Your anomaly was triggered, but it was eaten.

Because the using statement is actually try....Finally, your ** is equivalent to. >>>More

13 answers2024-02-09

You save the path in an XML and read it out the next time you start it.

27 answers2024-02-09

You can pass the main window as a parameter to a child window. >>>More