-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-23test.c
88 lines (68 loc) · 1.62 KB
/
1-23test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Programe to hold long input
it should happen the closest nth column
*/
#include <stdio.h>
#define MAXNUMBER 100 // Max number of input
void get_input(char input[], int lim);
void search_end_comment (int a, int b);
void check_quote (int c, int quote);
int main(){
char line[MAXNUMBER]; // current input line - string
get_input (line, MAXNUMBER);
printf("%s \n", line);
return 0;
}
/*
get_input: read inputs
arg[0]: char array - input text
arg[1]: int - the maimum limit of the length of input text (arg [0])
*/
void get_input(char input[], int lim){
int i, quote, c, d;
quote = 0;
for (i = 0; i < lim - 1 && (c = getchar()) != EOF; i++){
// check quote
if (c == '\'' || c == '"' ){
if (quote == 1){
quote = 0;
}
else {
quote = 1;
}
}
if ( c == '/' && !quote ){
if ((d = getchar()) == '*'){
search_end_comment (d, c);
i--;
}
else{
input[i] = c;
i++;
input[i] = d;
}
}
else {
input[i] = c;
}
}
input [i] = '\0';
}
/*
search_end_comment: serch the end of comment
They camn be omit
arg[0]: int - '*'
arg[1]: int - '/'
*/
void search_end_comment (int a, int b){
int c, d;
// get first 2
c = getchar();
d = getchar();
while (c != a || d != b){
d = getchar();
if (d == a){
c = d;
}
}
}