Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by anonymous ( 15 years ago )
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* array [100];
int main()
{
char* token;
int i;
int pid;
int result;
char* input = NULL;
for(i = 0; i < 100; i++)
{
array[i] = malloc(128);
}
while(1)
{
getline(&input;, NULL, stdin);
token = strtok(input, " ");
strcpy(array[0], token);
i = 1;
while((token = strtok(NULL, " ")) != NULL)
{
strcpy(array[i], token);
i++;
}
array[i] = NULL;
free(input);
pid = fork();
if(pid = -1)
{
puts("invalid fork.");
}
else if(pid > 0)
{
result = wait(pid);
if(result != pid)
{
puts("wait failed.");
}
}
else
{
result = execvp(array[0], array);
puts("ERROR");
}
}
for(i = 0; i < 100; i++)
{
free(array[i]);
}
}
Revise this Paste