-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetl.c
More file actions
54 lines (52 loc) · 862 Bytes
/
getl.c
File metadata and controls
54 lines (52 loc) · 862 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
#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 <limits.h>
#include <math.h>
#define FALSE 0
#define TRUE 1
#define SEND_MAX 100000
#define SERVER_LIST_SIZE 10000
/* getline */
char *getl(int len){
char temp[len];
char c[2];
temp[0] = '\0';
int i =0;
while(i<len){
c[0] = getchar();
if(c[0] == '\n'){
break;
}
else if(c[0] == '\b'){
if(i==0){
continue;
}
else{
--i;
temp[i] = '\0';
}
}
else{
++i;
c[1] = '\0';
strcat(temp, c);
}
}
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);
return 0;
}