-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_space.c
More file actions
56 lines (53 loc) · 979 Bytes
/
remove_space.c
File metadata and controls
56 lines (53 loc) · 979 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <pthread.h>
#include <netdb.h>
#include <math.h>
#define FALSE 0
#define TRUE 1
#define SEND_MAX 100000
void remove_space(char *s){
char *saveptr1;
char *str;
char t[strlen(s)+1];
strcpy(t, s);
str = strtok_r(s, " ", &saveptr1);
strcpy(s, str);
while( (str=strtok_r(NULL, " ", &saveptr1))!=NULL ){
strcat(s, str);
}
}
/* getline */
char *getl(int len){
char temp[len];
char c[2];
temp[0] = '\0';
int i =0;
for(i=0; i<len; i++){
c[0] = getchar();
if(c[0] != '\n'){
c[1] = '\0';
strcat(temp, c);
}
else{
break;
}
}
char *s = (char*)malloc( (strlen(temp)+1)*sizeof(char));
strcpy(s, temp);
return s;
}
int main(int argc, char** argv){
char *line = getl(1000);
printf("%s\n", line);
remove_space(line);
printf("%s\n", line);
return 0;
}