C Language String Practice Workbook
Problems and Solutions
1. Count Frequency of Each Character
char str[100]; int freq[256] = {0}; ...
2. Convert Lowercase to Uppercase
for(int i = 0; str[i] != '\0'; i++) if(str[i] >= 'a' && str[i] <= 'z') str[i] -= 32;
3. First Non-Repeating Character
for(int i = 0; str[i]; i++) freq[(unsigned char)str[i]]++; ...
4. Remove All Vowels
if(!isVowel(str[i])) result[j++] = str[i];
5. Check for Anagram
for(i = 0; i < len1; i++) count[str1[i]]++, count[str2[i]]--;
6. Remove All Whitespaces
if(str[i] != ' ' && str[i] != '\t') result[j++] = str[i];
7. Toggle Case
if(str[i] >= 'A' && str[i] <= 'Z') str[i] += 32; else if(str[i] >= 'a' && str[i] <= 'z') str[i] -= 32;
8. Most Frequent Character
freq[(unsigned char)str[i]]++; if(freq[...] > max) ...
9. Check if String Contains Only Digits
if(!isdigit(str[i])) isDigit = 0;
10. Replace Spaces with Hyphens
if(str[i] == ' ') str[i] = '-';