đŸ§ĩ C String Practice Problems

⬅️ Previous

đŸ§ĩ C String Practice Problems with Solutions

Here are beginner-level string problems in C with full explanations and code. Great for beginners learning string handling, character arrays, and C logic.

✅ Problem 1: Count Vowels and Consonants

#include <stdio.h>
#include <ctype.h>

int main() {
    char str[100];
    int vowels = 0, consonants = 0;
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    for(int i = 0; str[i] != '\0'; i++) {
        char ch = tolower(str[i]);
        if (ch >= 'a' && ch <= 'z') {
            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
                vowels++;
            else
                consonants++;
        }
    }
    printf("Vowels: %d\\nConsonants: %d\\n", vowels, consonants);
    return 0;
}

✅ Problem 2: Check Palindrome

#include <stdio.h>
#include <string.h>

int main() {
    char str[100], rev[100];
    int len, i;
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    len = strlen(str);
    if(str[len-1] == '\n') str[len-1] = '\0';
    for(i = 0; str[i] != '\0'; i++) {
        rev[i] = str[len - 2 - i];
    }
    rev[i] = '\0';
    if(strcmp(str, rev) == 0)
        printf("Palindrome\\n");
    else
        printf("Not Palindrome\\n");
    return 0;
}

✅ Problem 3: Convert to Uppercase Manually

#include <stdio.h>

int main() {
    char str[100];
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    for(int i = 0; str[i] != '\0'; i++) {
        if(str[i] >= 'a' && str[i] <= 'z') {
            str[i] = str[i] - 32;
        }
    }
    printf("Uppercase: %s", str);
    return 0;
}

✅ Problem 4: Reverse a String

#include <stdio.h>
#include <string.h>

int main() {
    char str[100], rev[100];
    int len, i;
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    len = strlen(str);
    if(str[len-1] == '\n') str[len-1] = '\0';
    for(i = 0; str[i] != '\0'; i++) {
        rev[i] = str[len - 2 - i];
    }
    rev[i] = '\0';
    printf("Reversed: %s\\n", rev);
    return 0;
}

✅ Problem 5: Count Character Occurrence

#include <stdio.h>

int main() {
    char str[100], ch;
    int count = 0;
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    printf("Enter a character to count: ");
    scanf(" %c", &ch);
    for(int i = 0; str[i] != '\0'; i++) {
        if(str[i] == ch)
            count++;
    }
    printf("'%c' occurred %d times.\\n", ch, count);
    return 0;
}
c string problems, c programming string exercises, practice problems with solution, c beginner string code, reverse string in c, check palindrome in c, uppercase conversion, count vowels, character array problems in c

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ