What is String? What are inbuild functions for processing string and different programs on Strings.
- 081. Print string in reverse,its length,in uppercase,lowercase and copy into another string
#include<stdio.h> #include<conio.h> #include<string.h> main() { char *s1,*s2; clrscr(); printf("Enter string : "); scanf("%s",s1); printf("Reverse String : %s",strrev(s1)); printf("Lenght: %d",strlen(s1)); printf("String in UPPER CASE : %s",strupr(s1)); printf("String in lower case : %s",strlwr(s1)); strcpy(s2,s1); printf("\nCopied string is...%s",s2); getch(); }
- 082. Write a program to accept a string and print no. of aphlabets, digits, special symbols present in it in C language
#include<stdio.h> #include<conio.h> #include<ctype.h> main() { char *s; int i,alphabets=0,digits=0,symbols=0; clrscr(); printf("Enter string : "); scanf("%s",s); for(i=0;s!='\0';i++) if(isalpha(s)) alphabets++; else if(isdigit(s)) digits++; else symbols++; printf("\nAphabets : %d",alphabets); printf("\nDigits : %d",digits); printf("\nSymbols : %d",symbols); getch(); }
- 083. Write a program to accept two strings and compare them in C language
#include<stdio.h> #include<conio.h> #include<string.h> main() { char *s1,*s2; clrscr(); printf("Enter string 1 : "); scanf("%s",s1); printf("Enter string 2 : "); scanf("%s",s2); if(strcmp(s1,s2)>0) printf("\nString 1 is greater.."); else if(strcmp(s1,s2)<0) printf("\nString 2 is greater.."); else printf("\nStrings are equal.."); getch(); }
- 084. Write a program to accept two strings and concatenate them in C language
#include<stdio.h> #include<conio.h> #include<string.h> main() { char *s1,*s2; clrscr(); printf("Enter string 1 : "); scanf("%s",s1); printf("Enter string 2 : "); scanf("%s",s2); printf("\nConcatinated string is...%s",strcat(s1,s2)); getch(); }
- 085. Write a program to print length of a given string in C language
#include<stdio.h> #include<conio.h> main() { int i,len=0; char *s; clrscr(); printf("Enter the string...."); scanf("%s",s); for(i=0;s!='\0';i++) len++; printf("The lenth of the string is...%d",len); getch(); }
- 086. Write a program to copy a string into another string in C language
#include<stdio.h> #include<conio.h> main() { int i; char *s1,*s2; clrscr(); printf("Enter the string 1...."); scanf("%s",s1); for(i=0;s1!='\0';i++) { s2; } s2='\0'; printf("The copied string is...%s",s2); getch(); }
- 087. Write a program to convert given string to UPPER CASE in C language
#include<stdio.h> #include<conio.h> main() { int i; char *s1; clrscr(); printf("Enter the string 1...."); scanf("%s",s1); for(i=0;s1!='\0';i++) { if((s1<='z')) s1-32; } printf("Resultant string is...%s",s1); getch(); }
- 088. Write a program to convert givern string to lower case in C language
#include<stdio.h> #include<conio.h> main() { int i; char *s1; clrscr(); printf("Enter the string 1...."); scanf("%s",s1); for(i=0;s1!='\0';i++) { if((s1<='Z')) s1+32; } printf("Resultant string is...%s",s1); getch(); }
- 089. Write a program to concatinate two strings in C language
#include<stdio.h> #include<conio.h> main() { int i,len=0,j; char *s1,*s2; clrscr(); printf("Enter the string 1...."); scanf("%s",s1); printf("Enter the string 2...."); scanf("%s",s2); for(i=0;s1!='\0';i++) { len++; } j=0; for(i=len;s2!='\0';i++) { s1; j++; } s1='\0'; printf("Resultant string is...%s",s1); getch(); }
- 090. Write a program to count no, of alphlabets, digits, special symbols in C language
#include<stdio.h> #include<conio.h> main() { int i,alphabets=0,digits=0,symbols=0; char *s; clrscr(); printf("Enter the string 1...."); scanf("%s",s); for(i=0;s!='\0';i++) { if(((s<='z'))) alphabets++; else if((s<='9')) digits++; else symbols++; } printf("\nAlphabets : %d",alphabets); printf("\nDigits : %d",digits); printf("\nSymbols : %d",symbols); getch(); }
- 091. Write a program to compare two strings in C language
#include<stdio.h> #include<conio.h> #include<process.h> main() { int i; char *s1,*s2; clrscr(); printf("Enter the string 1...."); scanf("%s",s1); printf("Enter the string 2...."); scanf("%s",s2); for(i=0;s1!='\0';i++) { if(s1) { if(s1) printf("\nString 1 is greater..."); else printf("\nString 2 is greater..."); getch(); exit(0); } } printf("String are equal...."); getch(); }
- 092. Write a program to count all vowels present in the string in C language
#include<stdio.h> #include<conio.h> main() { int i,vowel=0; char *s; clrscr(); printf("Enter the string 1...."); scanf("%s",s); for(i=0;s!='\0';i++) { if((s=='I')|| (s=='i')) vowel++; } printf("\nVowels : %d",vowel); getch(); }
- 093. Write a program to reverse the given string in C language
#include<stdio.h> #include<conio.h> main() { int i,j,len=0; char *s1,*s2; clrscr(); printf("Enter the string ...."); scanf("%s",s1); for(i=0;s1!='\0';i++) len++; j=0; for(i=len-1;i>=0;i--) { s2; j++; } s2='\0'; printf("\nReversed String : %s",s2); getch(); }
- 094. Write a program to check if the given string is palindrome or not
E.g. NITIN, LIRIL, MALAYALAM.
#include<stdio.h> #include<conio.h> #include<process.h> main() { int i,j,len=0; char *s1,*s2; clrscr(); printf("Enter the string ...."); scanf("%s",s1); for(i=0;s1!='\0';i++) len++; j=0; for(i=len-1;i>=0;i--) { s2; j++; } s2='\0'; for(i=0;s1!='\0';i++) if(s1) { printf("\nNot a palindrome"); getch(); exit(0); } printf("Palindrome"); getch(); }