Hogy-Bear

like dis

Mar 1st, 2018
238
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void toUpper(char *a);
  5.  
  6. int main(int argc, char const *argv[]) {
  7.  
  8.   char array[10]; //character array
  9.  
  10.   //get input
  11.   printf("%s", "Please enter a word no more than 10 characters long: ");
  12.   fgets(array, 10, stdin);
  13.  
  14.   toUpper(&array[0]);
  15.  
  16.   //print the changed string
  17.   printf("The changed string is %s", array);
  18.  
  19.   return 0;
  20. }
  21.  
  22. void toUpper(char *a){
  23.   //algorithm to convert to uppercase
  24.   while(*a != '\n'){ //while theres still characters left
  25.     if (*a >= 97 && *a <= 122){ //if character is lowercase
  26.       *a -= ('a' - 'A'); //convert it to uppercase.
  27.     }
  28.     a++; //increment to next memory location
  29.   }
  30. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment