-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmy_string.1.c
More file actions
43 lines (40 loc) · 1.16 KB
/
my_string.1.c
File metadata and controls
43 lines (40 loc) · 1.16 KB
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
34
35
36
37
38
39
40
41
42
43
/*******************************************************************************
*
* File Name : my_string.1.c
* Created By : Thomas Aurel
* Creation Date : January 18th, 2015
* Last Change : January 19th, 2015 at 00:05:39
* Last Changed By : Thomas Aurel
* Purpose : string specific functions (second file)
*
*******************************************************************************/
#include <stdlib.h>
#include "my_stdio.h"
#include "my_string.h"
char * my_strcapitalize(char *str){
char *string;
if ((string=(char *)malloc(my_strlen(str)*sizeof(char)))==NULL){
my_puts("ERROR: malloc failed\n");
return 0;
}
for(int i = 0; i < my_strlen(str); i++){
if(str[i] >= 'a' && str[i] <= 'z'){
string[i] = 'A' + str[i] - 'a';
} else {
string[i] = str[i];
}
}
return string;
}
int my_strcmp(char *s1, char *s2){
return my_strncmp(s1, s2, my_strlen(s2));
}
int my_strncmp(char *s1, char *s2, int n){
int i = 0;
my_puts("\n");
while(s1[i] == s2[i]){
my_printf("s1 : %c\ns2 : %c\n", s1[i], s2[i]);
i++;
}
return i-n;
}