-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest3.c
49 lines (36 loc) · 840 Bytes
/
test3.c
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
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <netdb.h>
void name_encode(char* name, char* name_encoded){
char *ptr;
int diff, i;
ptr = strchr(name, '.');
diff = ptr - name;
name_encoded[0] = diff;
for (i=0; i<strlen(name); i++){
name_encoded[i+1] = name[i];
if (name[i] == '.'){
ptr = strchr(&name[i+1], '.');
if (ptr == NULL){
printf("ptr null\n");
ptr = strchr(&name[i], '\0');
}
diff = ptr - &name[i] - 1;
name_encoded[i+1] = diff;
}
}
name_encoded[i+1] = 0;
/*printf ("%s, strlen=%lu\n", name_encoded, strlen(name_encoded));*/
}
int main(){
char buff[500];
name_encode("www.mail.ru.gggggg.fff", buff);
return 0;
}