Saturday, April 16, 2016

W.A.P to take input of String Character by Character using Unbuffered Input.

#include<stdio.h>
#include<conio.h>
void main()
{
char s[20];
int i;
clrscr();
printf("Enter a string :");
for(i=0;s[i-1]!=13;i++)
{
if(i==19)
{
s[i]='\0';
printf("Limit over");
break;
}
s[i]=getche();
}
if(i!=19)
{
s[i-1]='\0';
}
printf("\n%s",s);
getch();
}

OR

#include<stdio.h>
#include<conio.h>
void main()
{
char s[20];
int i;
clrscr();
printf("Enter a string :");
for(i=0;s[i-1]!='\n';i++)
{
scanf("%c",&s[i]);
}
s[i-1]='\0';

printf("\n%s",s);
getch();
}

No comments:

Post a Comment