I want to convert lowercase letters to uppercase letters through pointers. The code below doesn't work, it throws some error.
#include<stdio.h>
int main()
{
char somearray[10]; char mask;
mask = 1 << 5;
mask = ~mask;
char *someptr;
gets(somearray);
puts(somearray);
someptr =&somearray[0];
while (*someptr != '\n')
{
*someptr = *someptr & mask ;
someptr++;
}
printf("%s",someptr);
return 0;
}
got an ERROR:
not able to compile , if compiled runtime error
Even the below code doesnt work:
#include <stdio.h>
int main()
{
char somearray[10];
char mask;
char *someptr;
mask = 1 << 5;
mask = ~mask;
fgets( somearray, sizeof(somearray), stdin ); /* gets() is suspect: see other reactions */
puts(somearray);
for ( someptr = somearray; *someptr != '\0';someptr++)
{
*someptr &= mask ;
}
printf("%s",someptr);
return 0;
}
input : abcd output: abcd., expected : ABCD