char malloc + uknown characters
query=(char *)malloc(100*sizeof(char));
printf("String meta to malloc %s \n",query); Hi i have some problems with the dynamic allocation of char... These two lines give the a string that is not empty String meta to malloc \uffff\uffff\u0777 P.s The string returns me instead of an empty string some square boxes.... that cannot be print here |
Ok... you never assigned a value to query.
|
malloc() does not initialize the memory block that it returns. The contents of the memory will contain whatever was last placed in it by any previously run program. You should initialize the memory block to zeros before actually doing anything useful with it. You can use any number of functions such as memset(), or bzero() to perform this initialization.
|
As stated above, all malloc does is ask the system to set aside a block of n bytes for use by that program, and then give the address back to the program. It is up to you to put something in that memory.
|
All times are GMT -5. The time now is 02:28 AM. |