-1

I am doing a game where user have to enter coordinates: F5, H8

For example.

I want to do this in a 'for' loop but it is working only for first time, further it is not working well. I'm looking for any advice.

    #include <stdio.h>
#include <stdlib.h>
int k,z,x;
char y;
int main()
{
    for(k=1;k<=10;k++)
    {
printf("Enter letter and digit\n");
    scanf("%c %d",&y,&x);
    printf("%c %d\n",y,x);
    }
    return 0;
}
Damian
  • 11
  • 1

1 Answers1

0

Simple mod:

scanf(" %c %d",&y,&x);
       ^

What's that space? A space in scanf() format string consumes and discards all whitespaces if present. So spaces, tabs and newlines won't bother anymore.

From standard

A directive composed of white-space character(s) is executed by reading input up to the first non-white-space character (which remains unread), or until no more characters can be read. The directive never fails.

user2736738
  • 30,591
  • 5
  • 42
  • 56
iBug
  • 35,554
  • 7
  • 89
  • 134