Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CMD_LINE 500
void chk_for_redirect(char *fun_tknzd, char *opt_rdrct_2, char *inpt_rdrct_2);
int main(void)
{
char *str_tknzd[MAX_CMD_LINE], *opt_rdrct = NULL, *inpt_rdrct = NULL, test[] = ">tester";
str_tknzd[1] = test;
// this function is returning NULL for opt_rdrct and I am not sure why
// I think my problem is here
chk_for_redirect(str_tknzd[1], opt_rdrct, inpt_rdrct);
// this is how I know it is returning NULL
printf("Output redirect out of function: %s\n", opt_rdrct);
printf("Input redirect out of function: %s\n", inpt_rdrct);
return 0;
}
void chk_for_redirect(char *fun_tknzd, char *opt_rdrct_2, char *inpt_rdrct_2)
{
if(strchr (fun_tknzd, '>') == fun_tknzd){
opt_rdrct_2 = strchr (fun_tknzd, '>');
printf("Output redirect: %s\n", opt_rdrct_2);
}
else if(strchr (fun_tknzd, '<') == fun_tknzd){
inpt_rdrct_2 = strchr (fun_tknzd, '<');
printf("Input redirect: %s\n", inpt_rdrct_2);
}
}
The value that opt_rdrct_2 & inpt_rdrct_2 point to are not being passed to opt_rdrct and inpt_rdrct.
Thanks in advance for the help