Write a program that reads a string and counts occurrences of a given character.
#include <string.h>int main(){char s[1000], c;int i, count = 0;printf("Enter the string : ");gets(s);printf("Enter character to be searched: ");c = getchar();for (i = 0; s[i]; i++){if (s[i] == c){count++;}}printf("character '%c' occurs %d times \n ", c, count);return 0;}
Write a program convert character into Toggle character.
/*C program to toggle each character in a string.*/#include <stdio.h>int main(){char str[100];int counter;printf("Enter a string: ");gets(str);// toggle each string charactersfor (counter = 0; str[counter] != NULL; counter++){if (str[counter] >= 'A' && str[counter] <= 'Z')str[counter] = str[counter] + 32; // convert into lower caseelse if (str[counter] >= 'a' && str[counter] <= 'z')str[counter] = str[counter] - 32; // convert into upper case}printf("String after toggle each characters: %s", str);return 0;}
Write a program that checks whether the string is palindrome or not using string library function.
#include <stdio.h>#include <string.h>int main(){char s[1000];int i, n, c = 0;printf("Enter the string : ");gets(s);n = strlen(s);for (i = 0; i < n / 2; i++){if (s[i] == s[n - i - 1])c++;}if (c == i)printf("string is palindrome");elseprintf("string is not palindrome");return 0;}
0 Comments