473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

change the address of one element of int table?

Is it possible to change the address of one element of int table?
My program would be much simpler, if the first element of the table
would be same as last one. I mean:
int *s;
s=(*int)malloc(sizeof(int)*10);
…..
and no mater what I would do to this table I want s[0]==s[9] to be
true.
How to do this?

dopiotrko
Sep 20 '08 #1
5 1382
do*******@o2.pl wrote:
Is it possible to change the address of one element of int table?
My program would be much simpler, if the first element of the table
would be same as last one. I mean:
int *s;
s=(*int)malloc(sizeof(int)*10);
You mean `(int*)', and it would be even better to leave
it out altogether.
…..
and no mater what I would do to this table I want s[0]==s[9] to be
true.
How to do this?
There's no direct way: s[0] and s[9] are separate objects
and are able to hold different values. You'll need to exercise
some discipline of your own, such as

1) Whenever you store to either of them, store to the other
as well.

2) Instead of accessing s[i], access s[i % 9] (you can make
the array one place smaller in this case).

3) Don't access the elements of s[] directly, but always
through an array of pointers `int *sp[10]' which has
been initialized so sp[0] = &s[0], sp[1] = &sp[1], ...,
sp[8] = &s[8], sp[9] = &s[0 /* not 9 */].

--
Eric Sosman
es*****@ieee-dot-org.invalid
Sep 20 '08 #2
Thanks.
Very helpful
Especially last option.

dopiotrko

Sep 20 '08 #3
Thanks.
Very helpful
Especially last option.

dopiotrko

Sep 20 '08 #4
do*******@o2.pl writes:
Thanks.
Very helpful
Especially last option.
I may also be worth considering a circular linked list. Once set up,
you can repeat:

use(list_ptr->value);
list_ptr = list_ptr->next;

as often as you like, cycling round the values.

--
Ben.
Sep 20 '08 #5
<do*******@o2.plwrote in message news:
Very helpful
Especially last option.
Essentially you don't want an array, you want a wrapped buffer.

So maybe a structure and some macros

typedef struct
{
int *buff;
int capacity;
} CIRCULAR;

int getval(c, i) (c)->buff[(i)%(c)->capacity]

void putval(c, i, value) (c)->buff[(i)%(c)->capacity] = (value)

is the way to go.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Sep 20 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
13
by: Gary | last post by:
I have a table with a form consisting of several checkboxes and I'm wondering if its possible to change the table row background color on mouseover or hover and make it stay that color when the...
19
by: chee.k.cheng | last post by:
Hi, I'm wondering if it is possible to change the starting address of a structure element. For example, I have the following structure: struct demo { char digit; char alpha; } an;
12
by: Eric Lindsay | last post by:
I'm trying to learn how to read a DTD I wanted to use, http://www.w3.org/TR/html4/strict.dtd to ensure I was treating each element correctly in terms of being block, inline, or flow (either). ...
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
6
by: Jakob Bieling | last post by:
Hi, I want to move an element from a std::list to the end of the same list. To get this done, I thought I'd just do something like: std::list <intlst; lst.push_back (0); lst.push_back (1);...
3
by: rlueneberg | last post by:
I want to change the color of an "a" child element inside a table cell via javascript. Is there any way to do that? Ps: there is no id assigned to child elements. I would like to discover the child...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.