Exemplo n.º 1
0
int main(void){
	
	char prompt[100];
	char *initialprompt = "Yo bitch.";
	//copy the initial prompt into prompt array for changing
	memcpy(prompt, initialprompt, strlen(initialprompt)+1);
	printf("%s %s", prompt, " ");
	
	char userinput[100];
//	printf("%s", userinput);
//	printf("%d", isQuit(userinput));
//	printf("%d", isSetPrompt(userinput));
	while(gets(userinput) != NULL){
	//the user inputs valid things

		if(isSetPrompt(userinput) == 1){
		//we want to set the prompt
		//get subString also sets the prompt
			getSubstring(prompt, userinput);
		}
		if(isQuit(userinput) == 1){
		//we want to quit	
			exit(0);
		}
		else{
			system(userinput);
		}
		printf("%s %s", prompt, " ");
	}
}
Exemplo n.º 2
0
int main(void)
{
	char prompt[100]="$SAM: ";
	char *input=(char *)malloc(sizeof(char)*100);
	printf("%s",prompt);
	gets(input);
	while(!isExit(input))
	{
		 if(isSetPrompt(input))
		{
			char *token = strtok (input," ");
			token = strtok (NULL, " ");
			token = strtok (NULL, " ");
			strcat(token," ");
			strcpy(prompt,token);
		}
		else
		{
			system(input);
		}
		printf("%s",prompt);
		gets(input);
	}
}