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,309
  • 3
  • 26
  • 37
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
  • 32,079
  • 22
  • 110
  • 197