473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

strncat copies junk values ....

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 ..
Nov 14 '05 #1
4 2579


Vaddina Prakash Rao wrote:
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 ..


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
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
pr********@gmail.com (Vaddina Prakash Rao) writes:
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*"


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++).

--
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.
Nov 14 '05 #3
Vaddina Prakash Rao wrote:
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 ..


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.

Nov 14 '05 #4
Vaddina Prakash Rao wrote:
.... snip ...
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 ..


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.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Denzil | last post by:
Hi, I am retrieving my DB values and setting them in the MyRS::DoFieldExchange(CFieldExchange* pFX) function. One of these records is a Long datatype and could be "Null" in the DB table. The...
2
by: Will | last post by:
I have a 1 page report which I want to print numerous copies of. The number of copies will be specified by the user. My problem is that I want each report to print the copy number of number of...
11
by: Vaddina Prakash Rao | last post by:
Good morning everyone, Can someone comment what is wrong with these statements .. #include <stdio.h> #include <stdlib.h> #include <string.h> main() { char *final, *s="abcdefghij"; int count...
4
by: Kelvin Moss | last post by:
Hi group, Am I guaranteed a null terminated string after using strncat if my destination buffer is big enough for n + 1 characters ? .... strncat(dest, source, n); Is dest == 0 after above...
16
by: Jeff | last post by:
Im trying to memcpy a buffer from a filled in simple structure. When I memcpy and then print the resulting buffer, I see 7 locations that have junk before my data starts. My data structure is: ...
14
by: HB | last post by:
As many of us know, when we send legitimate emails to real customers from our apps, those emails often end up in the Hotmail (and MSN -- and AOL, too) junk folder. I've done a lot of testing with...
1
by: Suja | last post by:
Hi All, I have a WIN32 DLL which pass some information to a .NET based application via the windows messages. When I try to convert this data in the managed code, I am getting junk data. Does any...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
1
by: ykhamitkar | last post by:
Hi there, I have created an MS Access application which is split in Frontend and backend (using Database Splitter) Sometimes while using the application ms access automatically puts some junk...
11
by: Bill Cunningham | last post by:
Strncat is supposed to be better than strcat for some reason I've read. Is this because of a potential buffer overflow? I have compiled properly and used strlen too and I just wonder what is the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.