program.exe < testscript.exeYou probably meant to type program.exe < testscript.txt ?
short c = fgetc(stdin);As a sidenote, this is the most inefficient way to read a file (you probably know). Reading in big chunks (or the whole file in one go) is often a lot faster.
program.exe < testscript.exe
You probably meant to type program.exe < testscript.txt ?
You can provide command line options under the menu "Project" --> "Set program's arguments". This is as close to what you want as possible. It does not redirect input, though (which you want). You could modify your program to work that way by adding 3-4 lines of code, though (which is the "correct" behaviour, anyway).
You can get input reditrection if you add a post-build step like cmd /C program.exe < testscript.txt. Note that this will run the program every time you build, and it will not show a console, but dump the output to the log window. Also, if your program freezes, Code::Blocks will wait forever (or until you kill the program).
short c = fgetc(stdin); As a sidenote, this is the most inefficient way to read a file (you probably know). Reading in big chunks (or the whole file in one go) is often a lot faster.
#include <stdio.h>
/* beginning of main() */
FILE *f;
f = argc > 1 ? fopen(argv[1], "rb") : stdin;
short *c = fgetc(f); /* or whatever */
fclose(f);
/* end of main() */
short recordByte() {
for(;;) {
short c = fgetc(stdin);
if(isxdigit(c)) {
unsigned char retval;
if(isdigit(c)) {
retval = ...
}
.....
.....
c = fgetc(stdin);
if(!isxdigit(c)) {
....
}
return retval;
} else if(....) {
.....
.....
.....
}
return ...
}
}
This doesn't work for me, too, because the function to read every single Byte is not in main() but in another .c-file.Now be serious :) Then turn recordByte() into recordByte(FILE* f) (and the other function likewise), and pass on the file descriptor. Or, if you think that is too much hassle, just use a global variable which you initialise in main(). Global variables are not pretty, but they do the job for such a purpose.