I start to hate C, because I don't understand what's going on inside the primitives functions.
Why this example, doesn't read a txt fil.e The temp.txt exists and it's in the same path has the C file.
void redirect_in(char* cmd, char* file)
// unsigned char *buffer;
fd = fopen("./temp.txt", "r");
// pipe( pid );
//int fint = fork();
//if ( fint == 0 )
//dup2( fd, fileno( stdin ));// to read
//dup2( pid, fileno( stdout ));// to write
fseek(fd, 0, SEEK_END);
data = (char*) malloc(fileLen + 1);
//fread(buffer, fileLen, 1, fd);
//while (feof(fd) == 0)
// fgets(data, 10, fd); /* Read next record */
while(fgets(data, 80, fd) != NULL)
/* get a line, up to 80 chars from fr. done if NULL */
sscanf (data, "%s");
/* convert the string to a long int */
printf ("%s\n", data);
The C is killing me, because I don't understand what's going on.