User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 403,028 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 259 | Replies: 3 | Solved
Reply
Join Date: Jun 2008
Posts: 3
Reputation: bobraj is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bobraj's Avatar
bobraj bobraj is offline Offline
Newbie Poster

plz help-data manipulation in arrays

  #1  
Jun 11th, 2008
hi all,
i am new to programming,

my problem is that after certain data manipulation i will a array which will have only zeros & ones. (example x[5]={0,0,1,0,1}

now i would like to store the contents of the array in another variable like A(say)=00101.
but the codes which i written saves it as A=101.



code which wrote is
//
  1. p=0;
  2. A=0;
  3. for(i=0;i<=4;i++)
  4. {
  5. for(s=i;s<=5;s++)
  6. {
  7. p=10*p;
  8. }
  9.  
  10. A=A+(m[i]*p);
  11. p=1;
  12. }
  13.  
//
please help me
thank u
Last edited by Ancient Dragon : Jun 11th, 2008 at 7:48 am. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 3
Reputation: bobraj is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bobraj's Avatar
bobraj bobraj is offline Offline
Newbie Poster

Re: plz help-data manipulation in arrays

  #2  
Jun 11th, 2008
hi all,
i am new to programming & to this site,

plz let me clarify the problem further.

my problem is that after certain data manipulation (in a function) i will a array which will have only zeros & ones & twos. (example x[10]={0,0,1,0,1,2,2,2,2,2},x[10]={1,0,1,2,2,2,2,2,2,2},x[10]={0,0,0,1,1,1,0,0,2,2} etc...)

now i would like to store the contents of the array in another variable like A(say)=00101, A=101,A=00011100.
(ignoring all 2s but keeping all preceding 0s. 2s represent junk values )
but the codes which i written saves it as A=101,A=101,A=11100.



code which i wrote is
//
  1. int i,j,t,s;
  2. int A,p;
  3.  
  4. for(i=0;i<10;i++)
  5. {
  6. t=0;
  7. A=0;
  8. while(x[i]!=2)
  9. {
  10. t++;
  11. }
  12.  
  13. p=1;
  14. for(j=0;j<=t;j++)
  15. {
  16. for(s=t;s>=(t-j);s--)
  17. {
  18. p=10*p;
  19. }
  20.  
  21. A=A+(m[j]*p);
  22. p=1;
  23. }
  24.  
  25. }
//
please help me
thank u
Last edited by Ancient Dragon : Jun 11th, 2008 at 7:48 am. Reason: add code tags -- again
Reply With Quote  
Join Date: Jun 2008
Posts: 79
Reputation: Adak is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
Adak Adak is offline Offline
Junior Poster in Training

Re: plz help-data manipulation in arrays

  #3  
Jun 11th, 2008
May I suggest you use the digits 1, 2 & 3, instead of 0, 1, & 2?

Because you can't "make" a number which begins with 0's: 01, 001, 02, 002, etc., are not a number. Anything beginning with a real number, would be fine though: 101, 20, 103, etc.

Other idea's would include using bit values within the bytes, but that sounds unnecessarily difficult for a beginner, and keeping the values in an integer array, where the zero's would be fine.

Always put your code between code tags on any forum.
Last edited by Adak : Jun 11th, 2008 at 3:28 am.
Reply With Quote  
Join Date: Jun 2008
Posts: 3
Reputation: bobraj is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bobraj's Avatar
bobraj bobraj is offline Offline
Newbie Poster

Re: plz help-data manipulation in arrays

  #4  
Jun 11th, 2008
Originally Posted by Adak View Post
May I suggest you use the digits 1, 2 & 3, instead of 0, 1, & 2?

Because you can't "make" a number which begins with 0's: 01, 001, 02, 002, etc., are not a number. Anything beginning with a real number, would be fine though: 101, 20, 103, etc.

Other idea's would include using bit values within the bytes, but that sounds unnecessarily difficult for a beginner, and keeping the values in an integer array, where the zero's would be fine.

Always put your code between code tags on any forum.




thanks for helping. solved the problem
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C Forum

All times are GMT -4. The time now is 10:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC