Writing the key
value to the file is making the program crash. I know this because I substituted the key
value for a normal String
and the program worked fine. Why is the key
value making the program crash?
#include <stdio.h>
#include <conio.h>
int main() {
FILE *fp;
fp = fopen("C:\\Users\\Francisco\\Documents\\C programs\\log.txt", "w");
int key;
while(1) {
if(_kbhit()) {
key = _getch();
fprintf(fp, (const char*) key);
}
}
fclose(fp);
return 0;
}