printf("\nThe Result is : %s %s %s %s %s %s %s %s\n",var[0],var[1],var[2],var[3],var[4],var[5],var[6],var[7]);

while executing this i get correct result upto var[4]....
and for var[5] and var[6] im geting some garbage valuess, then for var[7] im getg my result...
whats wrong in my code.....

wouldn't it have been a lot simpler to have coded it with a loop

int i;
printf(\nThe Result is : ");
for(i = 0; i < 7; i++)
   printf("%s ", var[i]);

>>whats wrong in my code.....
how did you declare and initialize array var ? Most likely the problem is uninitialized data.

ummmm....
how can you giv print to a single variable var with %s specifier???

your problem shouldn't be in the code but the definition of var[]!

ummmm....
how can you giv print to a single variable var with %s specifier???

Are you referring to the code I posted? I'm assuming var is an array of character arrays. It works because I used a loop that starts the variable i at 0 and increments it by one on each loop iteration. If you don't know about loops yet then you should read up on them.

ummmm....
how can you giv print to a single variable var with %s specifier???

your problem shouldn't be in the code but the definition of var[]!

We don't know how it is declared, do we? It might be a 2D array or an array of Pointers or may be even vectors, the op should give more details if he/she wants a good answer

Comments
Yeah, that and many other possible horrors

Are you referring to the code I posted? I'm assuming var is an array of character arrays. It works because I used a loop that starts the variable i at 0 and increments it by one on each loop iteration. If you don't know about loops yet then you should read up on them.

i meant to reply to op's post!
he should hav posted the definition of the the array for better understanding of the problem!

This article has been dead for over six months. Start a new discussion instead.