Last active
December 16, 2015 03:38
-
-
Save jacobabrahamb4/5370939 to your computer and use it in GitHub Desktop.
convert to upper case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// find more explanations here | |
// https://www.securecoding.cert.org/confluence/display/seccode/STR30-C.+Do+not+attempt+to+modify+string+literals | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
char *strptr = NULL, *copy = NULL; | |
strptr = "Jacob Abraham"; // this will be stored in a read only location hence cannot be modified. | |
char str[]="Jacob Abraham"; // instead if str is used , it can be used to modify the array at anytime during the runtime. | |
int i, size=0; | |
printf("%p \n",strptr); | |
for(copy=strptr;*copy!='\0';copy++,size++,printf("original --> %c \n",*copy)) | |
{ | |
printf("%c \n",(*copy>='a'&& *copy<='z')?('A'+*copy-'a'):(*copy)); | |
//*copy=(*copy>='a'&& *copy<='z')?('A'+*copy-'a'):(*copy); // this is not allowed. | |
} | |
printf("%p \n",strptr); | |
printf("%s", strptr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment