cfunctionc-stringspalindrometolower

Palindrome, to lower function


Currently have a assignment from school to make a C program that checks if a user entered string is a palindrome or not. The program need to have 2 different functions (not counting the main function) and one is that checks if a string is a palindrome or not, and one that makes it so that the program recognize an uppercase letter as a lowercase letter. Example: the program recognize both "wow" and "Wow" as palindromes, as of now it only recognize the first one and not the second one. I have currently no clue how to proceed and help is much appriciated.

This is how my code currently looks:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define _CRT_SECURE_NO_WARNINGS


int checkPalindrome(char* text) 
{
    int i, c = 0, l; 
    l = strlen(text); 
    for (i = 0; i < l / 2; i++)
    {
        if (text[i] == text[l - i - 1])
            c++; 

    }
    if (c == i)
        return 1; 
    else
        return 0; 
}

int setToLowercase()
{

}

int main()
{
    char text[1000]; 

    printf("Enter  the string: ");

    gets(text); 


    if (checkPalindrome(text)) 
        printf("string is palindrome"); 
    else
        printf("string is not palindrome"); 

    return 0;
}

Solution

  • If you're allowed, tolower() will convert a character to lowercase. Loop for string.

    Otherwise take a gander at an ascii chart and figure the math/if case out.