RE: [Dev-C++] One other minor problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-04-13 11:40:32
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Khalid El-Kary > Sent: Sunday, April 13, 2003 6:24 AM > To: Dev...@li... > Subject: Re: [Dev-C++] One other minor problem > > > > >//for char**: > >char **str_arr; > >int num_of_elements = 5; > >str_arr = (char**) malloc(num_of_elements*sizeof(char*)); > > > >//the for each element of that array you should malloc > >str_arr[0] = (char*) malloc(10*sizeof(char); > > //sorry meant: > str_arr[0] = (char*) malloc(10*sizeof(char)); > > //note the last bracket *shy* The castings above are completely unnecessary in C. E.g. str_arr = malloc(num_of_elements*sizeof(char*)); In C, a void * is implicitly converted back to any pointer type. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net Anti-racism movement: http://www.positive-youthfoundation.org Iraq Peace Pledge: http://www.peacepledge.org |