Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
2
Indexable
Never
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char str1[100], str2[100], str3[100], str4[100];

    // Using strcmp function
    printf("Enter a string: ");
    scanf("%s", str1);
    printf("Enter another string: ");
    scanf("%s", str2);

    if (strcmp(str1, str2) == 0) {
        printf("The strings are equal.\n");
    } else {
        printf("The strings are not equal.\n");
    }

    // Using strcat function
    printf("\nEnter the first part of the string: ");
    scanf("%s", str1);
    printf("Enter the second part of the string: ");
    scanf("%s", str2);
    strcpy(str3, str1);
    strcat(str3, str2);
    printf("Concatenated string: %s\n", str3);
    
    // Using strcmpi function (case-insensitive comparison)
    printf("\nEnter a string for case-insensitive comparison: ");
    scanf("%s", str1);
    printf("Enter another string: ");
    scanf("%s", str2);

    if (strcmp(str1, str2) == 0) {
        printf("The strings are equal.\n");
    } else {
        printf("The strings are not equal.\n");
    }
    
    // Converting string to lowercase and uppercase
    printf("\nEnter a string to convert to lowercase: ");
    scanf("%s", str1);
    for (int i = 0; str1[i]; i++) {
        str4[i] = tolower(str1[i]);
    }
    
    str4[strlen(str1)] = '\0';
    printf("Lowercase string: %s\n", str4);
    printf("\nEnter a string to convert to uppercase: ");
    scanf("%s", str1);
    for (int i = 0; str1[i]; i++) {
        str4[i] = toupper(str1[i]);
    }
    
    str4[strlen(str1)] = '\0';
    printf("Uppercase string: %s\n", str4);
    return 0;
}