1
#include<stdio.h>

int main()
{
    int n,i;

    scanf("%d",&n);
    char vote[n];

    for(i=0;i<n;i++)
    {
        scanf("%c",&vote[i]);
    }

    for(i=0;i<n;i++)
    {
        printf("%c",vote[i]);
    }

    return 0;
}

It doesn't get second value, after getting first value it prints the first value .
If I give 3 for n it have to get three char values and it have to print that three char values , but code does not work properly for that.

Saurav Rastogi
  • 9,575
  • 3
  • 29
  • 41
Manikandan
  • 11
  • 3

1 Answers1

0

Buffer problem in scanf. Adding a space in the scanf because %c does not skip white space and terminate.

scanf(" %c",&vote[i]); instead of scanf("%c",&vote[i]);

msc
  • 33,420
  • 29
  • 119
  • 214