sorry i didnt post the whole thing ... but i found the solution?
i did this:
old::
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
char incmd[MAX];
char *cmd[64];
char *cdcmd[64];
char *cddir[64];
char *andfinder;
int i, j, pid, status, ret_value, tmp;
int isBEx = 0;
j = 0;
while (j < i) {
andfinder = cmd[j];
while ((strcmp(andfinder, "\0")) == 1) {
if (strcmp(andfinder, "&") == 0) {
printf("you found a AND sign\n");
isBEx = 1;
andfinder = "Y";
printf("%s\n", cmd[j]);
}
andfinder++;
}
j++;
}
exit(EXIT_SUCCESS);
} new::
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
char incmd[MAX];
char *cmd[64];
char *cdcmd[64];
char *cddir[64];
char *andfinder;
int i, j, pid, status, ret_value, tmp;
int isBEx = 0;
j = 0;
while (j < i) {
andfinder = cmd[j];
while ((strcmp(andfinder, "\0")) == 1) {
if (strcmp(andfinder, "&") == 0) {
printf("you found a AND sign\n");
isBEx = 1;
printf("%s\n", cmd[j]);
}
andfinder++;
}
j++;
}
if (isBEx == 1)
{
j = i;
andfinder--;
*andfinder = '\0';
} basically, i took it out of the loop and did it seperately? kinda weird ......
i did it in C ..compiling with gcc ...
error message was something about casting from int to char or something to that sort ....
here is my whole code, which works ... its just a basic minishell program... executes basic commands, and if needed, Ctl-C stops whatever your running (like an infinite loop) while not stopping the whole shell itself ..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
const int MAX = 1024;
int bgp;
void prntcmd ();
void ctlC_h(int sig);
int main()
{
char incmd[MAX];
char *cmd[64];
char *cdcmd[64];
char *cddir[64];
char *andfinder;
int i, j, pid, status, ret_value, tmp;
int isBEx = 0; /* 0 = NO executes in background 1 = executes in background*/
signal(SIGINT, ctlC_h);
while (1)
{
prt_prompt:
printf("sh%% ");
fgets (incmd, MAX, stdin);
if (strcmp(incmd, "\n") == 0)
goto prt_prompt;
i = 0;
cmd[i] = strtok (incmd," \n\t");
while (cmd[i] != NULL) {
i++;
cmd[i] = strtok(NULL," \n\t");
}
j = 0;
while (j<i)
{
andfinder = cmd[j];
while ((strcmp(andfinder, "\0")) == 1)
{
if (strcmp(andfinder, "&") == 0)
{
isBEx = 1;
}
andfinder++;
}
j++;
}
if (isBEx == 1)
{
j = i;
andfinder--;
*andfinder = '\0';
}
if (strcmp(*cmd, "bye") == 0)
break;
if (strcmp(*cmd, "?") == 0)
prntcmd();
if (strcmp(*cmd, "cd") == 0)
chdir(cmd[1]);
isBEx = 0;
pid=fork();
if (pid==0)
{
if (strcmp(*cmd, "?") != 0 && strcmp(*cmd, "cd") != 0)
execvp(*cmd, cmd);
exit(0);
}
else if (pid>0)
{
if (isBEx == 0)
ret_value=wait(&status);
}
}
return 0;
}
void prntcmd ()
{
printf(" ls -- list files in current directory\n");
printf(" cd <dir_name> -- change directory\n");
printf(" emacs <file_name> -- opens emacs file editor\n");
printf(" ps -- lists current processes\n");
printf(" mk <dir_name> -- creates a new directory\n");
printf(" rm <file_name> -- deletes the filename\n");
printf(" cp <old file_name> <new file_name> -- copies the file to a new file\n");
printf(" ? -- brings up this menu\n");
}
void ctlC_h(int sig)
{
}