View Single Post
  #6  
Old 08-27-2006, 19:03
Zest
 
Posts: n/a
Hi,
Thank you so much everybody who has tried to help me in this topic.
I learned some new points in programming by looking at your skillfully
coded programs in this topic.

Sorry but,I still have some problems and I hope you can shed some lingt
to clarify the obscure points.

I know that,as a convention, the name of an array is the same as the address
of its first element.
So when you want to use an array in scanf() function you don't need to use
ampersand operator(&) with its name and you just type the name of the array.
But for the second or other elements of that array you need to use (&) to be able
to point at the address of that element.
But this rule is not devised for printf() function.
In printf() function you can easily type the name that element and the printf() function shows
what is inside that element.

For example if you have an array witch is named exp your prohgram should work considering following
statements:

int exp[20]= {0};

exp == &exp[0];

so

scanf("%d",exp); // it should work properly

but for the second element you should code this statemant:

scanf("%d",&exp[1]);

but for printf you can just use this statement:

printf("%d",exp[0]); //without ampersand operator

I hope up to now I'm correct about this rule.

But in your code I can see that you have used ampersand operator with
both of the functions scanf() and printf().

For example ARC has used these statements:

***
scanf("%s",&pi[i*10]);

printf("%s\n",&pi[i*10]);
***

Again JuneMouse has used these ones:

***
scanf("%s%n",&pi[wen],&len[i]);

printf("%s",&*(pi + foo ));
***

Maybe I'm cionfused because we are using pointers in the program and you
can use ampersand in this way while you have pointers.

Could you please explain the fact?
Also let me know if we can use pointer without the ampersand operator
in out code.

The second obscure point for me is to know how this part of program works:


wen = wen + len[i]+ 1; //first time we need to add a 0 terminator
else
wen = wen + len[i]; // from second time no need coz it will point right

I want to know why we shouldn't increment "wen + len[i]" in the second time.
what will happen here that we don't need to add it to one?


If you don't mind please explain.
Thanks in advance.
Best Regards,
Zest.
Reply With Quote