PDA

View Full Version : Incompatible Types in Assignment?


nAzGiRl2005
11-08-2005, 07:17 PM
I have the following lines of code, and on the lines where I have used the "strtok" function, I'm getting this error: "Incompatible Types in Assignment". Please help me find out what's wrong:


int main()
{
char func_str[10];
char *func;
char name[10];
char phone[10];
while(1)
{
printf("please enter function:\n");
func = gets(func_str);

printf("**%c**\n", func);

char delim[] = " "; // space delimeter

if(func[0]=='i')
{
name = strtok(func, delim);
printf("%s",name);
phone = strtok(func, delim);

printf("%s", phone);
insert(name,phone);
break;
}
}
}

_Dan
11-08-2005, 08:50 PM
char name[10];
char phone[10];

should just be pointers e.g.

char *name;
char *phone;

nAzGiRl2005
11-08-2005, 09:49 PM
I tried that, but then I get these warnings:
"Assignment makes pointer from integer without a cast"

What should I do to get rid of these warnings? they're affecting the performance.

_Dan
11-08-2005, 10:12 PM
Which assignment? If it's the strtoks you could try
name = (char *) strtok(func, delim);
although strtok should return a char pointer I think. so that shouldn't happen.
if they're just warnings they shouldn't hurt.

nAzGiRl2005
11-08-2005, 10:18 PM
thanks!

one more question, how can I parse the following string to get name and phone number from it?

i name number

when I use strtok with space as the delimeter, the first string it returns is "i"... how do I get it to return name and number so I can store each of them into two different strings?

_Dan
11-08-2005, 10:28 PM
To get the 2nd, 3rd etc... put NULL as the string to continue with the 1st string.
e.g.
name = strtok(func, delim);
printf("%s",name);
phone = strtok(NULL, delim);
printf("%s", phone);