-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.cpp
87 lines (83 loc) · 2.31 KB
/
input.cpp
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
#include"header.h"
#define max_word_len 100
#define max_words 100
char** input(bool& pflag, bool& rflag)
{
char **ptr;
char ch;
int lv1 = -1, lv2=0;
bool line_end = false;
bool enter;
pflag = false;
rflag = false;
ptr = new char*[max_words];
/*if(ptr[1] == NULL)
cout<<"NULL func\n";*/
//ptr = NULL;
do{
ch = getchar();
lv2=0;
//cout<<"beg lv1 lv2 "<<lv1<<' '<<lv2<<endl;
enter = true;
while(ch == '\n' || ch == ' ')
{
//cout<<"parsing space\n";
if(ch == '\n')
{
//cout<<"encountered newline\n";
line_end = true;
enter = false;
break;
}
ch = getchar();
}
//cout<<"extra spaces\n";
//ptr[lv1] = NULL;
if(enter)
{
//cout<<"incrementing lv1\n";
++lv1;
//cout<<"incremened to "<<lv1<<endl;
ptr[lv1] = new char[max_word_len];
//cout<<"allotted mem to ptr"<<lv1<<endl;
while(1)
{
//++lv1;
if(ch != ' ' && ch != '\n' && ch != '\0')
{
//cout<<"inserting character "<<ch<<" at "<<lv1<<' '<<lv2<<endl;
ptr[lv1][lv2] = ch;
if(ch == '>')
rflag = true;
else if(ch == '|')
pflag = true;
//cout<<"inserted "<<ptr[lv1][lv2]<<endl;
++lv2;
ch = getchar();
}
else if(ch == ' ')
{
//cout<<"space break\n";
break;
}
//ch = getchar();
else if(ch == '\n')
{
line_end = true;
//cout<<"breakin away\n";
break;
}
}
//cout<<"inserted "<<ptr[lv1]<<" at index "<<lv1<<endl;
}
else
break;
//cout<<"end lv1 lv2 "<<lv1<<' '<<lv2<<endl;
}while(!line_end);
//cout<<"setin index "<<lv1+1<<" to null\n";
ptr[lv1+1] = NULL;
//cout<<ptr[0]<<endl;
/*if(ptr[1] == NULL)
cout<<"NULL\n";*/
return ptr;
}