Showing posts with label input. Show all posts
Showing posts with label input. Show all posts

Thursday 11 August 2016

Unformatted Input and output functions for string


Unformatted Input and output functions for string


#include<stdio.h>
void main()
{
           char s[10];
           printf("\nEnter a string: ");
           gets(s);                      //unformatted input
           printf("\nEntered string is: ");
           puts(s);                    //unformatted output
}

Output:
Enter a string: How are you
Entered string is: How are you

Formatted Input and output functions for string

Formatted Input and output functions for string


#include<stdio.h>
void main()
{
         char s[10];
         printf("\nEnter a string: ");
         scanf("%s", s);                  //formatted input

         printf("\nEntered string is: ");
         printf("%s", s);               //formatted output
}

Output:
Enter a string: How are you
Entered string is: How

Formatted Input and output functions for character

Formatted Input and output functions for character

#include<stdio.h>
void main()
{
          char ch;
          printf("\n Enter a character: ");
          scanf("%c", &ch);                          //formatted input
          printf("\n Entered character is: ");
          printf("%c", ch);                          //formatted output
}

Output:

1) Enter a character: h
    Entered character is: h

2) Enter a character: hii
    Entered character is: h