Read a certain length of string : Console Read Validation « Console « C / ANSI-C






Read a certain length of string

#include <stdio.h>

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

  scanf("%20s", str);
  printf("%s",  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.Narrow down the input by setting scanf
7.Narrow the input: letter and space