-1

When I try to compile this small program everything is correct but when I run it I find some problems. For example, I can't type the "c" variable in the second element of the table and so on.

#include <stdio.h> 

struct point{
    char c;
    int x,y;
};

int main(void)
{
    int size = 4;
    struct point tp[size];
    for(int i = 0; i < size; i++ )
    {
        printf("entrer le  nom du point no %d: ", i+1);
        tp[i].c = fgetc(stdin);
        printf("x = ");
        scanf("%d", &tp[i].x);
        printf("y = ");
        scanf("%d", &tp[i].y); 
    }
 }
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

There are a lots of similar questions here, for example: C scanf() and fgets() problem, fgets doesn't work after scanf.

You could use fgets() for user input and parse string with sscanf() for example.

Or you can use fgetc(stdin); after each scanf() to get rid of '\n' symbol.

Community
  • 1
  • 1
Pavel Krasavin
  • 165
  • 2
  • 11