CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

shift an array?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








shift an array?
PostPosted: Wed Feb 13, 2008 6:21 pm     Reply with quote

Hi,

how to shift values in an array, in a circular loop ?

example:

array[10] = {0,1,2,3,4,5,6,7,8,9}

shift + 1 the values (no values are lost)

to become:

array[10] = {1,2,3,4,5,6,7,8,9,0}

thank you

bye bye
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Feb 13, 2008 11:04 pm     Reply with quote

hi hi,

Sounds like a homework. Here's a tip: you need one additional variable to prevent the loss of data.

bye bye
_________________
Read the label, before opening a can of worms.
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 14, 2008 2:50 am     Reply with quote

Something like that ?
Code:
j=array[9] ;
for (i=0 ; i<9 ; i++) { array[9-i]=array[9-i-1] ; }
array[0]=j ;

Edit :oops, sorry, I was sleeping ! I shifted the array in the wrong direction... But sure you can do the change by yourself. Wink
Guest








PostPosted: Thu Feb 14, 2008 8:07 am     Reply with quote

Hi kender,

I'm just trying to learn some basics !

I have found a function named memmove ,, is this function more efficient ?

ccsinfo.com/forum/viewtopic.php?t=27272&highlight=memmove

But i think that is trying to do a FIFO (first in, first out)

If you know this function could you show me a simple example please Smile

thank you

simon
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Feb 14, 2008 12:23 pm     Reply with quote

Anonymous wrote:
Hi kender,

I'm just trying to learn some basics !

I have found a function named memmove ,, is this function more efficient ?

ccsinfo.com/forum/viewtopic.php?t=27272&highlight=memmove

But i think that is trying to do a FIFO (first in, first out)

If you know this function could you show me a simple example please Smile

thank you

simon


For a small array you cant beat simple direct byte moves.
Code:

j=array[0] ;
array[0]=array[1];
array[1]=array[2];
array[2]=array[3];
array[3]=array[4];
array[4]=array[5];
array[5]=array[6];
array[6]=array[7];
array[7]=array[7];
array[8]=array[9];
array[9]=j;
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group