gets():
It is a function defined within the header file
"stdio.h"
It is used to accept a line of text from the keyboard and
store into the specified character array.
Specification13:
Accept a line of text from the keyboard and print the number
of vowels, consonants, digits, space characters and special symbols.
Program:
#include<stdio.h>
void main()
{
char x[100];
char ch;
int i,vc=0,cc=0,dc=0,sp=0,ss=0;
clrscr();
printf("Enter
a line of text:");
gets(x);
for(i=0;x[i]!='\0';i++)
{
ch=x[i];
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
vc++;
else
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
vc++
else
if(ch>='b'&&ch<='z')
cc++;
else
if(ch>='B'&&ch<='Z')
cc++;
else
if(ch>='0'&&ch<='9')
dc++;
else if(ch=='
')
sp++;
else
ss++;
}
printf("Number
of vowels: %d\n",vc);
printf("Number
of consonents: %d\n",vc);
printf("Number
of digits: %d\n",vc);
printf("Number
of spaces: %d\n",sp);
printf("Number
of special symbols: %d\n",ss);
getch();
}
Execution:
Enter a line of text: Test signal,123
Number of vowels: 3
Number of consonants: 3
Number of digits: 3
Number of spaces: 1
Number of special symbols: 1
Array of strings:
A single dimensional character array is used to store a
string.
A two dimensional character array is used to store multiple
strings, where every row can store a string.
The address of each row is specified in scanf() and printf()
to accept and print individual strings.
Example:
#include<stdio.h>
void main()
{
char x[5][50];
int i;
clrscr();
printf("Enter
5 strings:\n");
for(i=0;i<5;i++)
scanf("%s",x[i]);
printf("The
given strings are:\n");
for(i=0;i<5;i++)
printf("%s\n",x[i]);
getch();
}
Execution:
Enter 5 strings:
make
it
small
and
simple
The given strings are:
make
it
small
and
simple
0 comments:
Post a Comment