hello,
Ths is Prashant....i am a new joinee....
I hv some confusion....can we change the size of array in runtime....if
so,then how
pls let me knw the answer
thanx 13 2452
prashu wrote: hello,
Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime....if so,then how
pls let me knw the answer
thanx
In a single word: look for information about "realloc".
Kind regards.
DISCLAIMER:
The proposed solution could not be valid if you are a programmer of the
UNIVAC or Manchester's Baby computer, if you work for embedded systems
for dishwashers, if you do not test it, and, in general, it is not
valid at all. Moreover, it is sure that is not standard, and undefined
behaviour.
prashu a écrit : I hv some confusion....can we change the size of array in runtime....if
ITYM 'have'
so,then how
If it was allocated with malloc(), yes, using realloc(). Isn't it a FAQ ?
You should also consider linked lists.
--
A+
Emmanuel Delahaye
Emmanuel Delahaye wrote: If it was allocated with malloc(), yes, using realloc().
Or allocated with another realloc, that is the most practical in lots
of situations:
void foo ( void )
{
char *a=NULL;
int max_elems=0;
while(...)
{
...
/* increase size */
max_elems++;
a=realloc(a,max_elems);
...
}
You should also consider linked lists.
From standard:
"An array type describes a contiguously allocated nonempty set of
objects with a particular member object type, called the element type".
Kind regards.
tmp123 a écrit : You should also consider linked lists.
From standard: "An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type".
Yes, but I was giving a design alternative. Sorry if was not clear enough.
--
A+
Emmanuel Delahaye
prashu wrote: hello,
Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime....if so,then how
pls let me knw the answer
thanx
I'm *perfectly certain* that you want the malloc/realloc route as suggested
here already, *but*, if you had a c99 compliant compiler, you could *sort of
do* what you're asking - "can we change the size of array in runtime" - by
using:
void func(int n)
{
int arr[n + 3];
// Use arr here
// ...
}
The runtime 'entity' arr's size can-change/changes according to the value of
'n' at each invocation.
Actually, as arr is created upon entry and destroyed on exit, I think you
could argue that it doesn't change, i.e., that as it's created, its size if
fixed, BUT, that you can cause any manifestation of it to have whatever size
you want (as long as n is an integer type). So, *if* you *weren't* wanting
the contents of your variable sized array to retain its contents, but wanted
something akin to malloc's flexibility in certain situations, you could use
it - and save the malloc/realloc/free calls.
I've not used it, but gcc has something like this [gnu's own variant] - so,
*if* you're using gcc, you could perhaps take a look at http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html, as it might be what
you're looking for (although I doubt it)
--
================================================== =============
In an attempt to reduce 'unwanted noise' on the 'signal' ...
Disclaimer:
Any comment/code I contribute might =NOT= be 100% portable, nor
semantically correct [read - 'not 100% pedantically correct'].
I don't care too much about that though, and I reckon it's the
same with most 'visitors' here. However, rest assured that any
'essential' (?) corrections WILL almost certainly appear v.soon
[read - 'to add noise as they see fit, *a pedant* will be along
shortly'].
WARNINGS: Always read the label. No beside-the-point minutiae
filter supplied. Keep away from children. Do not ignite.
================================================== =============
prashu wrote: Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime ....if so,then how
pls let me knw the answer
Lets get some things clear up front. This is Usenet (not google
groups). Google provides a very poor interface to Usenet. See my
sig. below for ways to use that broken interface intelligently.
You don't 'join' a newsgroup, you just use it. Anybody can.
However, you do not make things hard for other readers by using
silly abbreviations like hv, pls, knw, etc. Also use proper
punctuation, which .... is not.
One normally reads a newsgroup for a while to see what the
practices are. This is called lurking. When posting a question
ensure that it is clear, and that the subject adequately describes
it. The following references will clue you in: http://www.caliburn.nl/topposting.html http://www.netmeister.org/news/learn2quote.html http://www.catb.org/~esr/faqs/smart-questions.html http://www.greenend.org.uk/rjk/2000/06/14/quoting.html http://www.i-hate-computers.demon.co.uk/ http://web.ukonline.co.uk/g.mccaugha...ks/uquote.html
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
In message <43***************@yahoo.com>, CBFalconer
<cb********@yahoo.com> writes prashu wrote: Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime ....if so,then how
pls let me knw the answer
Lets get some things clear up front. This is Usenet (not google groups). Google provides a very poor interface to Usenet. See my sig. below for ways to use that broken interface intelligently.
You don't 'join' a newsgroup, you just use it. Anybody can. However, you do not make things hard for other readers by using silly abbreviations like hv, pls, knw, etc. Also use proper punctuation, which .... is not.
Actually the ellipsis (...) is perfectly valid punctuation, it normally
denotes that something has been removed.
--
------------------------------------------------------------------------
TQ - The Voice Of insanity
------------------------------------------------------------------------
u can only do that by using link list. u can add links to increase the
size of array..but for that u cant take normal c array n have to define
array as a class. read data structures. as*********@gmail.com wrote: u can only do that by using link list.
Only do what? Please provide context, people might not have seen and
might never see the article you are responding to. Please see http://cfaj.freeshell.org/google/ for details of how to do this.
Also please don't use contractions like "u" instead of you, they make is
far harder for others to read your posts.
u can add links to increase the size of array..but for that u cant take normal c array n have to define array as a class. read data structures.
C does not have classes, you might be thinking of a very different
language called C++.
In any case, there are other ways to do something very like expanding
arrays, such as using allocated memory and realloc to change the size as
others have already pointed out.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Tony Quinn <to**@sixpints.demon.co.uk> writes: In message <43***************@yahoo.com>, CBFalconer <cb********@yahoo.com> writesprashu wrote: Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime ....if so,then how
pls let me knw the answer
Lets get some things clear up front. This is Usenet (not google groups). Google provides a very poor interface to Usenet. See my sig. below for ways to use that broken interface intelligently.
You don't 'join' a newsgroup, you just use it. Anybody can. However, you do not make things hard for other readers by using silly abbreviations like hv, pls, knw, etc. Also use proper punctuation, which .... is not.
Actually the ellipsis (...) is perfectly valid punctuation, it normally denotes that something has been removed.
An ellipsis consists of 3 periods. "...." could be an ellipsis
followed by a period, but since it's not being used correctly anyway,
it's more likely just a bunch of dots.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Tony Quinn wrote: In message <43***************@yahoo.com>, CBFalconer <cb********@yahoo.com> writesprashu wrote: Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime ....if so,then how
<snip>
silly abbreviations like hv, pls, knw, etc. Also use proper punctuation, which .... is not.
Actually the ellipsis (...) is perfectly valid punctuation, it normally denotes that something has been removed.
Yes, but these consist of exactly 3 dots (as you have used
correctly), not four (this is c.l.c, after all). ;-)
Cheers
Vladimir
Keith Thompson wrote: Tony Quinn <to**@sixpints.demon.co.uk> writes: <cb********@yahoo.com> writes prashu wrote:
Ths is Prashant....i am a new joinee.... I hv some confusion....can we change the size of array in runtime ....if so,then how
pls let me knw the answer
Lets get some things clear up front. This is Usenet (not google groups). Google provides a very poor interface to Usenet. See my sig. below for ways to use that broken interface intelligently.
You don't 'join' a newsgroup, you just use it. Anybody can. However, you do not make things hard for other readers by using silly abbreviations like hv, pls, knw, etc. Also use proper punctuation, which .... is not.
Actually the ellipsis (...) is perfectly valid punctuation, it normally denotes that something has been removed.
An ellipsis consists of 3 periods. "...." could be an ellipsis followed by a period, but since it's not being used correctly anyway, it's more likely just a bunch of dots.
Why all this prattling about ellipsis? The point was to catch
Prashu (a potential googler and abbreviator) early and train
him/her into the acceptable practices on usenet. Reinforcement and
clarification of that message would be more productive.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
CBFalconer wrote: Keith Thompson wrote: Tony Quinn <to**@sixpints.demon.co.uk> writes: <cb********@yahoo.com> writes prashu wrote: > > Ths is Prashant....i am a new joinee.... > I hv some confusion....can we change the size of array in runtime > ....if so,then how > > pls let me knw the answer
Lets get some things clear up front. This is Usenet (not google groups). Google provides a very poor interface to Usenet. See my sig. below for ways to use that broken interface intelligently.
You don't 'join' a newsgroup, you just use it. Anybody can. However, you do not make things hard for other readers by using silly abbreviations like hv, pls, knw, etc. Also use proper punctuation, which .... is not.
Actually the ellipsis (...) is perfectly valid punctuation, it normally denotes that something has been removed.
An ellipsis consists of 3 periods. "...." could be an ellipsis followed by a period, but since it's not being used correctly anyway, it's more likely just a bunch of dots.
Why all this prattling about ellipsis? The point was to catch Prashu (a potential googler and abbreviator) early and train him/her into the acceptable practices on usenet. Reinforcement and clarification of that message would be more productive.
I rest my case.
--
================================================== =============
In an attempt to reduce 'unwanted noise' on the 'signal' ...
Disclaimer:
Any comment/code I contribute might =NOT= be 100% portable, nor
semantically correct [read - 'not 100% pedantically correct'].
I don't care too much about that though, and I reckon it's the
same with most 'visitors' here. However, rest assured that any
'essential' (?) corrections WILL almost certainly appear v.soon
[read - 'to add noise as they see fit, *a pedant* will be along
shortly'].
WARNINGS: Always read the label. No beside-the-point minutiae
filter supplied. Keep away from children. Do not ignite.
================================================== ============= This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: William C. White |
last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using
cURL? Our website is hosted on a shared drive and the webhost company
doesn't installed additional software (such as cURL)...
|
by: Albert Ahtenberg |
last post by:
Hello,
I don't know if it is only me but I was sure that header("Location:url")
redirects the browser instantly to URL, or at least stops the execution of
the code. But appearantely it continues...
|
by: James |
last post by:
Hi,
I have a form with 2 fields.
'A'
'B'
The user completes one of the fields and the form is submitted.
On the results page I want to run a query, but this will change
subject to which...
|
by: Ollivier Robert |
last post by:
Hello,
I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9
system. The link succeeds but everytime I try to run php, I get a SEGV from
inside the libcnltsh.so library.
...
|
by: Richard Galli |
last post by:
I want viewers to compare state laws on a single subject.
Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the...
|
by: Albert Ahtenberg |
last post by:
Hello,
I have two questions.
1. When the user presses the back button and returns to a form he filled
the form is reseted. How do I leave there the values he inserted?
2. When the...
|
by: inderjit S Gabrie |
last post by:
Hi all
Here is the scenerio ...is it possibly to do this...
i am getting valid course dates output on to a web which i have designed
....all is okay so far , look at the following web url
...
|
by: Jack |
last post by:
Hi All,
What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g.
select x from y where z=:parameter
Which in asp/jsp would be followed by some statements to bind a value...
|
by: Sandwick |
last post by:
I am trying to change the size of a drawing so they are all 3x3.
the script below is what i was trying to use to cut it in half ... I
get errors.
I can display the normal picture but not the...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |