Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void toUpper(char *a);
- int main(int argc, char const *argv[]) {
- char array[10]; //character array
- //get input
- printf("%s", "Please enter a word no more than 10 characters long: ");
- fgets(array, 10, stdin);
- toUpper(&array[0]);
- //print the changed string
- printf("The changed string is %s", array);
- return 0;
- }
- void toUpper(char *a){
- //algorithm to convert to uppercase
- while(*a != '\n'){ //while theres still characters left
- if (*a >= 97 && *a <= 122){ //if character is lowercase
- *a -= ('a' - 'A'); //convert it to uppercase.
- }
- a++; //increment to next memory location
- }
- }
Advertisement