Errors in my code..

hi this is srinivas..
here is my code.in this code iam getting errors at case 6 statement.please suggest me how to solve it.

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#include <fstream>
#include <iostream>
#include <utility>
#include <map>
using namespace std;
int nxtlnpos=0,npos=0,cj,i,j;
multimap<string,string> ckt;
string arr[20];
ifstream sfile;
string temp,newstr,ostr,wstr,nandop,nandip,instnm,inst,newtemp;
int pos=0,ipos=0,spacepos=0,semicpos=0,cpos[100],diff,spos=0;
int ch;
string s;
void display(string temp);
void display1(string temp);
void inst_name();
void inp();
void out();
void wire();
void inpout();
void inpout1();
void instance(string temp);
int main(int argc,const char * argv[]){
	for(;;){
		sfile.open("fulladd.v",ios::in|ios::binary);
		if(!sfile){
			cout<<"Cannot open the file"<<endl;
			exit(1);
		}
		cout<<"\n MENU\n";
cout<<"1--->inputs\n2--->outputs\n3--->details\n4--->inst_name\n5--->inpout\n6---->inst info\n7---->exit\n";
		cout<<"enter ur choice"<<endl;
		cin>>ch;
		switch(ch){
			case 1:	inp();
				break;
			case 2: out();
				break;
			case 3: wire();
				break;
			case 4: inst_name();
				break;
			case 5:	inpout();
				break;
			case 6: inpout1();
				cout<<"enter the searched item:::"<<endl;
				cin>>s;
				string search_item(s);
				typedef multimap<string,string>::size_type sz_type;
				sz_type entries=ckt.count(s);
				multimap<string,string>::iterator iter1=ckt.find(s);
				for(sz_type cnt=0;cnt != entries;++cnt,++iter1){
					cout<< "the elements are:::::::::"<<iter1->second <<endl;
				}
				break;
			case 7: exit(0);
			default:cout<<"useless fellow enter current choice\n";
		}
		sfile.close();
		sfile.clear();
        }
return 0;
}	
void inp(){
	cout<<"INPUT"<<endl;
	getline(sfile,temp);
	do
        {		
                spos = temp.find(";",0);
		while(spos < 0){
			getline(sfile,newtemp);
			temp = temp + newtemp;
			spos = temp.find(";",0);
		}
		pos = temp.find("input",0);
		if(pos == 1)
		{
                        spacepos=temp.find(" ",0);
			semicpos=temp.find(";",0);
			diff = semicpos-spacepos;
			newstr.assign(temp,spacepos+1,diff-1);
			cout<<" "<<newstr<<endl;			
		}
		getline(sfile,temp);
	}while(temp != "\0");
cout<<endl;
}
void out()
{
	cout<<"OUTPUTS INFORMATION"<<endl;
	getline(sfile,temp);
	do
        {	
                spos = temp.find(";",0);
		while(spos < 0){
			getline(sfile,newtemp);
			temp = temp + newtemp;
			spos = temp.find(";",0);
		}
		pos = temp.find("output",0);
                if(pos == 1){
			spacepos=temp.find(" ",0);
			semicpos=temp.find(";",0);
			diff = semicpos - spacepos;
			ostr.assign(temp,spacepos+1,diff-1);
			cout<<" "<<ostr<<endl;			
		}
		getline(sfile,temp);
	}while(temp != "\0");
	cout<<endl;
}
void wire()
{
	string temp,wstr;
	int spacepos=0,pos=0,semicpos=0,nxtlnpos=0,diff;
	cout<<"WIRES INFORMATION"<<endl;
	
	getline(sfile,temp);
	do{
		spos = temp.find(";",0);
		while(spos < 0){
			getline(sfile,newtemp);
			temp = temp + newtemp;
			spos = temp.find(";",0);
		}
		pos = temp.find("wire",0);
		if(pos == 1){
			spacepos=temp.find(" ",0);
			semicpos=temp.find(";",0);
			diff = semicpos - spacepos;
			wstr.assign(temp,spacepos+1,diff-1);
			cout<<" "<<wstr<<endl;			
		}
		getline(sfile,temp);
	}while(temp !="\0");
		cout<<endl;
}
void inpout()
{
	cout<<"DETAILED INFORMATION"<<endl;
        while(sfile){
		getline(sfile,temp);
		pos = temp.find("nand",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("nor",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("buffer",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("inv",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("xnor",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("xor",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("oai",0);
		if(pos!=-1){
		display(temp);				
		}
		pos = temp.find("ds",0);
		if(pos!=-1){
		display(temp);				
		}		
	}
	cout<<endl;
}
void display(string temp){
	int spacepos1=0,obrace = 0,oj = 0,cj = 0,cmj = 0,cbrace = 0,comma = 0,bracepos=0,compos=0,compos2=0;
	int cpos[100],obpos[100],cbpos[100];
	string nandip;
	for(int a=0;a<100;a++){
		cpos[a]=0;
		obpos[a]=0;
		cbpos[a]=0;
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == '('){
			++obrace;
			obpos[oj++]=index;
//			cout<<"OBPOS IS >>>>>>"<<index<<endl;
		}
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == ')'){
			++cbrace;
			cbpos[cj++]=index;
		}
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == ','){
		++comma;
		cpos[cmj++]=index;
		}
	}
	int k=0,ix=2;
	while(k<=comma){
		if(k==0){
			bracepos = obpos[1];
			compos = cbpos[0];
			int dif = compos - bracepos;
			nandip.assign(temp,bracepos+1,dif-1);
			cout<<nandip<<"  ";
		}
		else if(k==comma){
			bracepos = cbpos[cj-2];
			compos = obpos[oj-1];
			int dif = bracepos - compos;
			nandip.assign(temp,compos+1,dif-1);
			cout<<"\t\t "<<nandip<<endl;
		}
		else{
			while(ix!=obrace-1){
				compos = obpos[ix];
				compos2 = cbpos[ix-1];
				int dif = compos2 - compos;
				nandip.assign(temp,compos+1,dif-1);
				cout<<nandip<<"  ";
				ix++;
			}
		}
			k++;
	} 
	
}

void inst_name()
{
	cout<<"INST_NAME"<<endl;
	
	while(sfile){
		getline(sfile,temp);
	                pos = temp.find("nand",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("nor",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("buffer",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("inv",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("xnor",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("xor",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("oai",0);
			if(pos!=-1){
			instance(temp);				
			}
			pos = temp.find("ds",0);
			if(pos!=-1){
			instance(temp);				
			}		
	}
	cout<<endl;
	cout<<endl;
}
void instance(string temp)
{
	int bracepos=0,spacepos1=0,spacepos2=0,comma = 0,compos=0,compos2=0,dotpos=0;
	int j =0;
	if(pos == 1){
		spacepos1 = temp.find(" ",0);
                compos = temp.find("(",0);
		diff=compos-spacepos1;
       		instnm.assign(temp,spacepos1+1,diff-1);
		cout<<" "<<instnm<<endl;
}
}
void inpout1()
{	
	cout<<"DETAILED INFORMATION"<<endl;
        while(sfile){
		getline(sfile,temp);
		pos = temp.find("nand",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("nor",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("buffer",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("inv",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("xnor",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("xor",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("oai",0);
		if(pos!=-1){
		display1(temp);				
		}
		pos = temp.find("ds",0);
		if(pos!=-1){
		display1(temp);				
		}		
	}
	cout<<endl;
}		
      
void display1(string temp){
	int spacepos1=0,obrace = 0,oj = 0,cj = 0,cmj = 0,cbrace = 0,comma = 0,bracepos=0,compos=0,compos2=0;
	int cpos[100],obpos[100],cbpos[100];
	string nandip1,nandip2,nandip3;
	if(pos == 1){
		spacepos1 = temp.find(" ",0);
                compos = temp.find("(",0);
		diff=compos-spacepos1;
       		instnm.assign(temp,spacepos1+1,diff-1);
	}
	for(int a=0;a<100;a++){
		cpos[a]=0;
		obpos[a]=0;
		cbpos[a]=0;
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == '('){
			++obrace;
			obpos[oj++]=index;
		}
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == ')'){
			++cbrace;
			cbpos[cj++]=index;
		}
	}
	for(string::size_type index=0;index!=temp.size();index++){
		if(temp[index] == ','){
		++comma;
		cpos[cmj++]=index;
		}
	}
	int k=0,ix=2;
	while(k<=comma){
			if(k==0){
			bracepos = obpos[1];
			compos = cbpos[0];
			int dif = compos - bracepos;
			nandip1.assign(temp,bracepos+1,dif-1);
			ckt.insert(multimap<string,string>::value_type(instnm,nandip1));
		}
		else if(k==comma){
			bracepos = cbpos[cj-2];
			compos = obpos[oj-1];
			int dif = bracepos - compos;
			nandip2.assign(temp,compos+1,dif-1);
			ckt.insert(multimap<string,string>::value_type(instnm,nandip2));
		}
		else{
			while(ix!=obrace-1){
				compos = obpos[ix];
				compos2 = cbpos[ix-1];
				int dif = compos2 - compos;
				nandip3.assign(temp,compos+1,dif-1);
				ckt.insert(multimap<string,string>::value_type(instnm,nandip3));
				ix++;
			}
		}
		k++;
						
	} 
	
}
I got a couple of errors when I tried to compile it as follows:

Line 47:
cin >> s This created an error " error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
I did #include <string> and that sorted the problem.

Line 56
This created the error error C2360: initialization of 'iter1' is skipped by 'case' label
Enclose the code for the case:6 inside brackets like this to stop this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
case 6: 
{
	inpout1();
	cout<<"enter the searched item:::"<<endl;
	cin>>s;
	string search_item(s);
	typedef multimap<string,string>::size_type sz_type;
	sz_type entries=ckt.count(s);
	multimap<string,string>::iterator iter1=ckt.find(s);
	for(sz_type cnt=0;cnt != entries;++cnt,++iter1)
	{
		cout<< "the elements are:::::::::"<<iter1->second <<endl;
	}
				
	break;
}
		


Line 51,52,53,54 - I'm not an expert on containers but this loop does not seem right (maybe someone else can help you out here).

Last edited on
If you would post the errors you (srinivas) get, we could better help...
Line 51..54 don't look so bad, although it is always dangerous to mix iterator increments and a loop based on size / counting - you may end up with an iterator incremented beyond the size of the container.
Topic archived. No new replies allowed.