Hogy-Bear icon

like dis

Hogy-Bear | PRO | 03/01/18 02:27:39 PM UTC | 0 ⭐ | 194 👁️ | Never ⏰ | []
C |

670 B

|

None

|

0 👍

/

0 👎

#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
  }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎