strncat copies junk values ....

  • Thread starter Vaddina Prakash Rao
  • Start date
V

Vaddina Prakash Rao

Google was not able to retreive the message .. so I couldnt write a
followup .. I guess this one will be displayed as a new post ...

anyways, thank you all people for all your replies ..

can you please clear one more question ..

As you have said, the cast is not needed, in the following statement
...
final = (char *) malloc (count * sizeof(char));
if (!(final = (char *)malloc(count + 1)))

But when i execute the program without the cast, as below,
final = malloc (count * sizeof(char));
if (!(final = malloc(count + 1)))

i get the error
"Invalid conversion from void* to char*"

Any explanation for this ..

thanks again ..
 
M

Michael Mair

Vaddina said:
Google was not able to retreive the message .. so I couldnt write a
followup .. I guess this one will be displayed as a new post ...

anyways, thank you all people for all your replies ..

can you please clear one more question ..

As you have said, the cast is not needed, in the following statement
..




But when i execute the program without the cast, as below,




i get the error
"Invalid conversion from void* to char*"

Any explanation for this ..

thanks again ..

You are not using a C compiler to compile C.
You are using a C++ compiler to compile C. This is a Bad Idea
as even the "obvious" common subset of C and C++ is not the
real common subset.

Use a C compiler.


Cheers
Michael
 
K

Keith Thompson

Google was not able to retreive the message .. so I couldnt write a
followup .. I guess this one will be displayed as a new post ...

anyways, thank you all people for all your replies ..

can you please clear one more question ..

As you have said, the cast is not needed, in the following statement
..


But when i execute the program without the cast, as below,


i get the error
"Invalid conversion from void* to char*"

You're probably using a C++ compiler (C++ doesn't allow implicit
conversions from void* to char*).. Use a C compiler.

Your C and C++ compilers may be the same program. Typically the
suffix on the source file name determines which one is invoked (e.g.,
".c" for C, ".C", ".cc", or ".cpp" for C++).
 
M

Martin Ambuhl

Vaddina said:
As you have said, the cast is not needed, in the following statement
But when i execute the program without the cast, as below,
i get the error
"Invalid conversion from void* to char*"

Any explanation for this ..

You are using a C++ compiler. If the product you are using claims to be
able to compile C, a different language, then it has a method of
invoking it as a C compiler. Sometimes that is a simple as using ".c"
as the tail of the file name. Whatever it takes, use it. C++ is not C.
 
C

CBFalconer

Vaddina said:
.... snip ...

But when i execute the program without the cast, as below,


i get the error
"Invalid conversion from void* to char*"

Any explanation for this ..

You are using a C++ compiler or the C++ mode of a dual mode
compiler. Ensure your source files have the extension .c (lower
case) and examine and flags etc. used in operating your compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top