Vowels Consonant :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
char str[100];
int i, len, vowel, cons;
printf("\n\nCount total number of vowel or consonant :\n");
printf("----------------------------------------------\n");
printf("Input the string : ");
gets(str);
vowel = 0;
cons = 0;
len = strlen(str);
for(i=0; i<len; i++)
if(str[i] =='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u'
|| str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
vowel++;
else if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
cons++;
printf("\nThe total number of vowel in the string is : %d\n", vowel);
printf("The total number of consonant in the string is : %d\n\n", cons);
}
Rev Print String :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
char str[100]; /* Declares a string of size 100 */
int l,i;
printf("\n\nPrint individual characters of string in reverse order :\n");
printf("------------------------------------------------------\n");
printf("Input the string : ");
gets(str);
l=strlen(str);
printf("The characters of the string in reverse are : \n");
for(i=l;i>=0;i--)
printf("%c ", str[i]);
printf("\n");
}
Extraction & Substring :
#include <stdio.h>
void main()
char str[100], sstr[100];
int pos, l, c = 0;
printf("\n\nExtract a substring from a given string:\n");
printf("--------------------------------------------\n");
printf("Input the string : ");
gets(str);
printf("Input the position to start extraction :");
scanf("%d", &pos);
printf("Input the length of substring :");
scanf("%d", &l);
while (c < l)
sstr[c] = str[pos+c-1];
c++;
sstr[c] = '\0';
printf("The substring retrieve from the string is : %s", sstr);
}
Built In Functions in C :
// Built in functions of strings
#include <stdio.h>
#include <string.h>
int main () {
char str1[15] = "Hello";
char str2[15] = " World";
char str3[15];
int len ;
/* copy str1 into str3 */
strcpy(str3, str1);
printf("In str3 the contents is %s \n", str3 );
/* concatenates str1 and str2 */
strcat( str1, str2);
printf(" String concatenation result is %s\n", str1 );
/* total lenghth of str1 after concatenation */
len = strlen(str1);
printf("strlen(str1) : %d\n", len );
return 0;