[c Language] Input/output

Asked 6 days ago, Updated 6 days ago, 0 views

int main(void)

    Point p1, p2;
    printf ("Enter two coordinates."\n");
    for (int i = 0; i < 5; i++) {
        printf ("%dth input", i + 1);
        scanf_s("%d %d", &p1.x, &p1.y);
        scanf_s("%d %d", &p2.x, &p2.y);
    for (int i = 0; i < 5; i++) {
        printf("[%d,%d] [%d,%d]\n", p1.x, p1.y, p2.x, p2.y);

    return 0;


I made a function that inputs five, but all the other parts are solved Why does it print only the last input...? printf("[%d,%d] [%d,%d]\n", p1[i] in the printf function.x, p1[i].y, p2[i].x, p2[i].y)y); If I change it like this, there are a lot of errors suddenly, so how do I change it to print out the first input?


2022-09-20 14:23

1 Answers

If you want to receive a total of five coordinate pairs, the variable to store the input value must be in array form.

Point p1[5];
Point p2[5];


scanf_s("%d %d", &p1[i].x, &p1[i].y)y);


printf("[%d,%d] [%d,%d]\n", p1[i].x, p1[i].y, p2[i].x, p2[i].y)y);

2022-09-20 14:23

If you have any answers or tips

© 2022 pinfo. All rights reserved.