Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Conversão de letras minúsculas em letras maiúsculas */
- // Apple Xcode
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h> // toupper
- #define NCAR 80
- void func_uppercase(char *s)
- {
- // from lower case to upper case
- // return via pointer
- for (int i = 0; i < strlen(s); i++)
- {
- if (s[i] >= 'a' && s[i] <= 'z')
- {
- s[i] = (char)((int)s[i] + (int)'A' - (int)'a');
- }
- }
- }
- void func_uppercase2(char *s)
- {
- // lower case to upper case
- // return via pointer
- for (int i = 0; i < strlen(s); i++)
- {
- s[i] = toupper(s[i]);
- }
- }
- int main (int argc, const char * argv[])
- {
- // upper case
- char s[NCAR];
- // input string
- printf("string: ");
- fgets(s, NCAR, stdin);
- // converting "manually"
- func_uppercase(s);
- printf("manualmente: %s\n", s);
- // using toupper
- func_uppercase2(s);
- printf("usando toupper: %s\n", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement