Sunday 8 July 2012

c program print string

This program print a string. String can be printed by using various functions such as printf, puts.

C programming code

#include <stdio.h>
 
main()
{
    char array[20] = "Hello World";
 
    printf("%s\n",array);
 
    return 0;
}
To input a string we use scanf function.

C programming code

#include <stdio.h>
 
main()
{
    char array[100];
 
    printf("Enter a string\n");
    scanf("%s", array);
 
    printf("You entered the string %s\n",array);
    return 0;
}

Input string containing spaces

#include <stdio.h>
 
main()
{
   char a[80];
 
   gets(a);
 
   printf("%s\n", a);
 
   return 0;
}

0 comments:

Post a Comment