hey Quzah:
getting a compilation error. How do I fix??
error:
4 /accounts/student2/gcc copystring.c
copystring.c: In function `strdup':
copystring.c:21: warning: assignment makes pointer from integer without a cast
Code:
#include <stdio.h>
#include <string.h>
char *strdup(const char *str);
main()
{
char *s = strdup( "This is a test." );
printf("%s", s );
return 0;
}
char *strdup(const char *str)
{
char *result;
result = malloc(strlen(str)+1); <--- line 21
if (result == NULL) {
printf("Error: malloc failed ");
return NULL;
}
strcpy (result, str);
return result;
}