Well, I have the following code:
int main(int argc, char **argv, char **envp)
{
const char *usuario= NULL;
while(*envp)
{
char *str = *envp++;
//if(strcmp(str,"USERNAME")==0)
if(str[0] == 'U' && str[1] == 'S' && str[2]=='E' && str[3]=='R' && str[4] == 'N')
{
usuario = str;
break;
}
}
if(usuario != NULL)
{
printf("Hola, bienvenido al programa %s",usuario);
}
return 0;
}
And my question is why can't I declare the variable outside the while and initialize it inside?
char *str;
const char *usuario= NULL;
while(*envp)
{
*str = *envp++;
if(`...
The compiler says: warning: assignment makes integer from pointer without a cast
if(str[0] == 'U' && ... && str[4] == 'N'). It should be at least length 5, or the indexing breaks.*str = *envp++;is not an initialization. It's an assignment.