C
carmelo
Hi! I wrote this function that shoul read dinamically a string, but
the compiler gimes me this error:
error C2440: '=' : cannot convert from 'void *' to 'char *'
Why?
char *read_string(void)
{
int i=1;
char *string, c;
string=malloc(sizeof(char)); <----------------------- here
while(isspace(c=getchar()));
do
{
string = realloc(stringa,++i*sizeof(char));
<----------------------- here
string[i-2]=c;
string[i-1]='\0';
}
while(!(isspace(c=getchar())));
return stringa;
}
the compiler gimes me this error:
error C2440: '=' : cannot convert from 'void *' to 'char *'
Why?
char *read_string(void)
{
int i=1;
char *string, c;
string=malloc(sizeof(char)); <----------------------- here
while(isspace(c=getchar()));
do
{
string = realloc(stringa,++i*sizeof(char));
<----------------------- here
string[i-2]=c;
string[i-1]='\0';
}
while(!(isspace(c=getchar())));
return stringa;
}