Saturday 26 October 2013

Print String

1:- #include<stdio.h>
void main()
{
char a[]="welcome to C tutorials";
printf("%s",c);
}


2:- #include<stdio.h>
void main()
{
char a[20];
printf("enter the string:-");
scanf("%s",a);
printf("%s",a);
}


3:- #include<stdio.h>
void main()
{
char a[20];
printf("enter the string:-");
gets(a);
puts(a);
}

in program 1 we directly initialize the string at the time of declaration.

in program 2 we use scanf() for the input.

in program 3 we use gets() for the input.

Difference Between scanf() and gets():-

tha main difference between scanf and gets method is that scamf() method does not read the character after the blank spaces ..and gets () read full string including the spaces..

Example:-we use scanf() for input ...string:- "welcome to C tutorial"
on printing it  prints only "welcome" and ignore all the characters after the space..

if we use gets() for input then it prints whole string:-"welcome to C tutorial"


No comments :

Post a Comment