forked from riederm/exercise01__ToUpperCase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpperCase.c
More file actions
33 lines (27 loc) · 702 Bytes
/
UpperCase.c
File metadata and controls
33 lines (27 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
/*
* turns the given String into upper-case characters
*/
void toUpperCase(char* text){
u_int8_t i = 0;
while (text[i] != '\0'){
if ((text[i] > 96) && (text[i] < 123)){ //if ASCII code equals lowercase character
text[i] = text[i] - 32; //convert to uppercase
}
i++;
}
}
void test(char* text){
char* newString = malloc(strlen(text)*sizeof(char)+1);
strcpy(newString, text);
toUpperCase(newString);
printf("%s --> %s\n", text, newString);
}
int main(int argc, char const *argv[]) {
test("xyz");
test("this is a test");
return 0;
}