Mask-group

Examples



  1.  

  1.  

Both programs give the same output as KILNSMAN.

printf() can be used to print the characters of a string. The %s used in printf( ) is a format specification for printing out a string.

Note:  printf( ) doesn’t print the ‘\0’.

Example:

Output:

Enter your name Ekeeda

Hello Ekeeda

  • The declaration char name[25] sets 25 bytes under the array name[ ], whereas the scanf( ) function fills in the characters typed at keyboard into this array until the enter key is hit. Once enter is hit, scanf( ) places a ‘\0’ in the array. Naturally, we should pass the base address of the array to the scanf( ) function. 

  • While using scanf() we must take care of following things:

  1. The length of the string should not exceed the dimension of the character array. This is because the C compiler doesn’t perform bounds checking on character arrays.

  2. scanf( ) is not capable of receiving multi-word strings. Therefore names such as ‘Ekeeda Gate’ would be unacceptable.

  • To use multi-word strings we need to use the gets() and puts() function.

Example:

Output:

Enter your full name Ekeeda Gate

Hello!

Ekeeda Gate

note: puts( ) can display only one string at a time.