View Single Post
  #7  
Old 08-28-2006, 16:24
JuneMouse
 
Posts: n/a
best way is to think about it and draw out the sequnce either in your head or using some tools that you can gather

for example you could have opened excel layed out the entire memory
in a column and taken your input and filled each of memory values manually
and assigned them an address which would have cleared your doubts

try making flow charts, graphs layout diagrams or if you dont have the patience to do all this
open a debugger and step through your own code in assembly several times
and it will show you exactly what are you accessing with you i, foo ,wen,len etc


Code:
0	pi [0]	a					aaaaaaaa
1	pi [1]	a					bbbbb
2	pi [2]	a					ccccc
3	pi [3]	a					rr
4	pi [4]	a					eee
5	pi [5]	a					
6	pi [6]	a					
7	pi [7]	a					
8	pi [8]		len[0]=9 so wen = 10				
9	pi [9]						
10	pi [10]	b					
11	pi [11]	b					
12	pi [12]	b					
13	pi [13]	b					
14	pi [14]	b	len[1] = 6	so wen = 10+6  == 16			
15	pi [15]						
16	pi [16]	c					
17	pi [17]	c					
18	pi [18]	c					
19	pi [19]	c					
20	pi [20]	c	len[2] = 6	so wen = 16+6 ==22			
21	pi [21]						
22	pi [22]	r					
23	pi [23]	r	len[3] =3 so wen = 22 +3 ==25				
24	pi [24]						
25	pi [25]	e					
26	pi [26]	e					
27	pi [27]	e	len[4] = 4 wen = 25+4 ==29				
28	pi [28]						
29	pi [29]						
30	pi [30]						
31	pi [31]						
32	pi [32]						
33	pi [33]						
34	pi [34]						
35	pi [35]						
36	pi [36]						
37	pi [37]						
38	pi [38]						
39	pi [39]						
40	pi [40]						
41	pi [41]						
42	pi [42]						
43	pi [43]						
44	pi [44]						
45	pi [45]						
46	pi [46]						
47	pi [47]						
48	pi [48]						
49	pi [49]						
50	pi [50]
basically no one over here was or will be willing to nitpick your program

every one has thier own stereotypes (they read i cant use malloc and they glance at your code ) and they normally will code thier own variations

they would never care if you used (&*(pi) or &pi
and the answers will not reflect on these points

you are supposed to learn these finer points of & and * and (*) and &* and *& and *(&) and &(*) by reading through books and or practicing
coding and answering the true or false questions in those books

if you really note those true or false questions in the books will obviously have all the above variations

anyway i just cleared up the doubt about your not taking string and i provided a referance solution

its neither foolproof nor submissible as evidence in some doctoral thesis

i borked out at the first working sequnce of code that took least modification from your original code i havent checked up *& &* etc

and may be you dont need to add the null terminator even the first time
and directly do wen = wen + len[i]

i did not check i added that block of if else just to be sure
not because its etched in steel rule

glance through the code and grasp the bigger picture
you wont find answers to finer points in any ones code
unless you ask a specific question (like how do you use * and &) and then you will be directed to some c c++ newbie forum or may be some one will post a refernace to k&r or bjarnes book still you wont get a right exact answer

get a book practice (repeat thier examples in hard copy ) make typos change
the examples find what errs find why it errs
and after a few days of time you wont be asking these question but will be
doing the right thing without you even observing you did it right
Reply With Quote