Domanda

So I'm getting this warning in the last line of this block of code I wrote.

int main(int argc, char **argv)   
{
 while(1) {
char buffer[400];
char str;

if(strcmp(argv[1],"start") == 0 )
    { printf("myshell: process has started \n");
            int i=0;
            while (str = strtok(buffer," ") == NULL) {          
            argv[i] = str;  //**This line causes the warning!

Is it because of how I declare str? Is that incorrect? Thank you!

As the title suggests, the warning is warning: assignment makes point from integer without cast.

È stato utile?

Soluzione

I'm not sure how this could result in a cast error but I do see an error in your code. The first call to strtok initializes the token'izer since you pass it a buffer. The second call, assuming you want it to find the next token, should have a null value instead of the same buffer.

Look at this example...

So what you want is:

...
int i=0;
str = strtok(buffer, " ");
do {          
    argv[i] = str;  //**This line causes the warning!
    ...
} while (str = strtok(NULL, " ") != NULL);

Altri suggerimenti

The prototype of strtok() is char *strtok(char *str, const char *delim);, the return value of strtok() is char *, therefore the type of str should be char *.

What is more, str = strtok(buffer," ") == NULL means str = (strtok(buffer," ") == NULL), probably not what you want, I guess you mean (str = strtok(buffer," ")) == NULL.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top