954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting garbage value

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.....

skprasat
Newbie Poster
13 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Hi,
Think there's a problem with var[] array.mention details

tksrules
Newbie Poster
21 posts since Feb 2009
Reputation Points: 7
Solved Threads: 1
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

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

axyelp
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 
ummmm.... how can you giv print to a single variable var[i] 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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

ummmm.... how can you giv print to a single variable var[i] 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

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 
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!

axyelp
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You