C
ceo
hi,
why do i get the following error? do i need to explicitly typecast the
pointer returned by malloc to char *?
thanks,
ceo
[root@lin1 tmp]# cat malloc.cpp
#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main() {
char *s = NULL;
s = malloc(sizeof( char) * 10);
strcpy(s, "blah blah");
printf("\n%s\n", s);
return 0;
}
[root@lin1 tmp]# gcc malloc.cpp
malloc.cpp: In function `int main ()':
malloc.cpp:8: cannot convert `void *' to `char *' in assignment
[root@lin1 tmp]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-108.1)
[root@lin1 tmp]#
why do i get the following error? do i need to explicitly typecast the
pointer returned by malloc to char *?
thanks,
ceo
[root@lin1 tmp]# cat malloc.cpp
#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main() {
char *s = NULL;
s = malloc(sizeof( char) * 10);
strcpy(s, "blah blah");
printf("\n%s\n", s);
return 0;
}
[root@lin1 tmp]# gcc malloc.cpp
malloc.cpp: In function `int main ()':
malloc.cpp:8: cannot convert `void *' to `char *' in assignment
[root@lin1 tmp]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-108.1)
[root@lin1 tmp]#