Narrow down the input by setting scanf : Console Read Validation « Console « C / ANSI-C






Narrow down the input by setting scanf

  
#include <stdio.h>

int main(void)
{
  char str[80];

  printf("Enter letters, anything else to stop\n");
  scanf("%[a-zA-Z]", str);

  printf(str);

  return 0;
}


           
       








Related examples in the same category

1.Reading monetary amounts separated by commas and spaces
2.Reading types of strings from the keyboard
3.Exercising formatted input
4.Characters in the format control stringCharacters in the format control string
5.Read only a range of char
6.Read a certain length of string
7.Narrow the input: letter and space