What's the difference between

char   *Name;
Name = malloc (13*sizeof(char));
strcpy (Name, "George Brown");

and

char   Name[13];
strcpy (Name, "George Brown");

The compiler gives a warning in the second case: warning C4047: 'function' : 'char *' differs in levels of indirection from 'char *[13]' & warning C4024: 'strcat' : different types for formal and actual parameter 1 . The warning goes away if we cast the static array as (char*) . Is it dangerous though?

In which case I would say you're not posting the code you're compiling.

The only way to get those warnings with VC++ is to do this

char   Name[13];
    strcpy ( [B]&[/B]Name, "George Brown");

As written, both snippets are fine.

You're right. I was mistaking LPSTR datatype to be a char where it is defined as char* . Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.