STRING
String
// To pass a string to the function////
#include<stdio.h>
#include<conio.h>
void main()
{
void get_string(char*);
char name[30];
printf("\n enter your name");
scanf("%s",&name);
get_string(name);
getch();
}
void get_string(char*name)
{
printf("hello %s",name);
}
result
enter your name: brijesh
hello brijesh
// To find the length of the string using the strlen (string)////
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char str[30];
printf("\n Enter a string: ");
scanf("%s",&str);
printf("the lenght of the string is: %d ",strlen(str));
getch();
}
// To copy a string using strcpy(string)////
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char strs[30],strd[30];
printf("\n Enter a string: ");
scanf("%s",&strs);
strcpy(strd,strs);
printf("the copied string is: %s ",strd);
1
STRING
getch();
}
// To combine two string using strcat (string)////
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char strs[30],strd[30],str[30];
printf("\n Enter a string: ");
scanf("%s",strs);
printf("Enter another string:");
scanf("%s",strd);
strcat(strs, strd);
printf("the combined string is: %s ", strs );
getch();
}
Result
Enter a string brijesh
Enter another string sing
The combined string is: brijeshsingh
/// To count of the vowels of a string///
#include<string.h>
#include<stdio.h>
#include<conio.h>
main()
{
int found=0,count=0,k;
char str[30];
printf("Enter a string");
gets(str);
for(k=0;str[k]!='\0';k++)
{
switch(str[k])
{
case'a':
case'e':
case'i':
case'o':
2
STRING
case'u':
case'A':
case'E':
case'I':
case'O':
case'U':
count++;
}
}
printf("the no of vowel in this string is %d",count);
getch();
}