Can I convert a structure string to an integer?

Asked 2 years ago, Updated 2 years ago, 124 views

int main()
{
    void pid_sort(struct id[], int);
    void pid_print(struct id[], int);
    struct student stu[3];
    int count;
    int i;

    printf ("Enter 3 student information");

    for (i = 0; i < 3; i++)
    {
        printf ("Name: ");
        scanf_s("%s", stu[i].name, sizeof(stu[i].name));
        printf ("Department: ");
        scanf_s("%s", stu[i].subject, sizeof(stu[i].subject));
        printf ("resident registration number: ");
        scanf_s("%s", stu[i].pid, sizeof(stu[i].pid));


        stu[i].S_Y = stu[i].pid[6];
        stu[i].year = stu[i].pid[0]*10 + stu[i].pid[1];
        stu[i].month = stu[i].pid[2]*10 + stu[i].pid[3];
        stu[i].day = stu[i].pid[4]*10 + stu[i].pid[5];


If you enter student information as a school assignment, you need to get the correct output If you enter your ID number, you have to show your date of birth and leap year or not If you look at the code, change the resident number you received as char to int I was going to make it like this, xx, xx, xx. xx. However, the values of year, month, and day are entered as ASCII code values and cannot be used as atoi, so I post the question like this

c struct char int

2022-09-20 22:18

1 Answers

I answer myself As the ASCII code has increased, it works right away when I do -48.


2022-09-20 22:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.