I though, if I cast number like this (unsigned char)32 , will be enough to fix the compiler warning, but it was not the way I planned.
Here I have the following part of the program that really explains the problem:
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void){ char *ptr = malloc(6); const char *name = "MICHI"; unsigned int i = 0; if(ptr){ strcpy(ptr, name); ptr[strlen(ptr)] = '\0'; }else{ return 1; } while(ptr[i] != '\0'){ if((ptr[i] >= 'A') && (ptr[i] <= 'Z')){ ptr[i] += (unsigned char)32; } i++; } printf("Name = %s\n",ptr); if(ptr){ free(ptr); ptr = NULL; } }
When I try to compile it with compiler warnings, I get the following:
error: conversion to 'char' from 'int' may alter its value [-Werror=conversion]|
This means that the next ptr[i] += (unsigned char)32; doesn't provide a solution to my problem.
My question is how to discard this warning because I have no idea about it.
Ideone does not help, because I think all warnings are disabled.
c casting
Michi Feb 16 '16 at 17:50 2016-02-16 17:50
source share