Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Wednesday, May 28, 2014

C program print string

C programming code

#include <stdio.h>
#include<conio.h> 
void main()
{
    char array[20] = "Hello World";
    clrscr();
    printf("%s\n",array);
    getch();
}

To input a string we use scanf function.

C programming code

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

Input string containing spaces

#include <stdio.h>
#include<conio.h> 
void main()
{
   char a[80];
   clrscr(); 
   gets(a);
   printf("%s\n", a);
   getch();
}
**Note that scanf can only input single word strings, to receive strings containing spaces use gets function.

No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC