This is my input function:
int i,j,n,len,c;
char *buffer = 0;
size_t bufsize = 0;
ssize_t characters;
characters = getline(&buffer, &bufsize, stdin);
len = strlen(buffer);
buffer[len-1]='\0';
if (characters > 0)
{
char *end_str1;
char *token1 = strtok_r(buffer, ";", &end_str1);
int count = 0, wordcnt;
while (token1 != NULL)
{
char cmd[10][101];
memset(cmd,0,sizeof(cmd));
wordcnt = 0;
char *end_str2;
count++;
char *token2 = strtok_r(token1, " ", &end_str2);
while (token2 != NULL)
{
n = strlen(token2);
strncpy(cmd[wordcnt],token2,n);
wordcnt++;
token2 = strtok_r(NULL, " ", &end_str2);
}
cmd[wordcnt+1][0]='\0';
execvp(cmd[0],cmd);
token1 = strtok_r(NULL, ";", &end_str1);
}
}
free(buffer);
The only warning is incompatible pointer type, but my cmd array is a **ptr, so I don't understand what is wrong.
I tried equating it to **k, and then passing that into execvp. Didn't work. I tried changing cmd into a **cmd, I think I did something wrong there, because it should have worked but it didn't.
cd ..; pwdare stored in buffer.