[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [linuxiran] [OT] C programming, variable size array
From: |
Arash Bijanzadeh |
Subject: |
Re: [linuxiran] [OT] C programming, variable size array |
Date: |
Sat, 13 Dec 2003 11:54:25 +0330 |
User-agent: |
KMail/1.5.4 |
On Saturday 13 December 2003 00:15, Aryan Ameri wrote:
> On Friday 12 December 2003 22:05, Arash Partow wrote:
> > Hi Aryan,
> >
> > There are 2 important methods malloc and realloc
> > malloc allocated memory and realloc as its name
> > suggests allow you to re-allocate more memory from the OS.
> >
> >
> > ie:
> >
> > /*
> > create dynamic array, guess an initial size in your case....
> > */
> >
> > int myArraySize = 123;
> > char* myArray = (char*)malloc(sizeof(char)*myArray);
> >
> > if(myArray == NULL)
> > {
> > printf("!-ERROR-! System could not allocate memory...\n");
> > }
> > .
> > .
> > .
> > now lets say you want to add more to the array but you've
> > reached the limit of the array.
> >
> > int additionalLength = 123;
> > if ((myArray =
> > (char*)realloc(myArray,sizeof(char)*(myArraySize+additionalLength))
> > == NULL) {
> > printf("!-ERROR-! System could not re-allocate memory...\n");
> > }
> >
> > .
> > .
> > .
> >
> >
> > If you have anymore questions feel free to ask.
>
> I just studied pointers, but I didn't yet know of the existence of
> malloc and realoc. Anyway, your code, as well as these functions man
> pages are now putting me in the right direction. Thanks for the help.
>
> And I want to be bold, and ask again, cause this is really important for
> me: Anyone know of any C mailing list? (pretty strange that I can't
> find one!!).
>
> Cheers
You can use gcc mailing lists. They are really helpful.
--
Don't go around saying the world owes you a living. The world owes you
nothing. It was here first.
-- Mark Twain
- [linuxiran] [OT] C programming, variable size array, Aryan Ameri, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Aryan Ameri, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Kaveh Mousavi, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Mohammad Reza Ghorbani, 2003/12/13
- Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/13
Re: [linuxiran] [OT] C programming, variable size array, Hossein S. Zadeh, 2003/12/13