logo

Convert string to Lowercase in C

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char *argv[]) { char str[] = "This is an EXAMPLE String"; size_t length = strlen(str); // int diff = ('a' - 'A'); for (size_t i = 0; i < length; i++) { // if (str[i] >= 'A' && str[i] <= 'Z') { // str[i] += diff; // } if (isupper(str[i])) { str[i] = tolower(str[i]); } } printf("Result is: '%s'\n", str); return 0; }