How can I get input to stop at 'Esc' instead of \n ?
I'm using Code::Blocks 10.05 in Win XP SP3.
How can I get input to stop at 'Esc' instead of \n ?
This is the line of my code I'm having trouble with:
Code:
fgets(entry, sizeof(entry), stdin);
I'd like to know how to input text with line breaks and then exit input when 'Esc' is pressed e.g.:
Code:
Things I did this morning\n
\n
Things I did this afternoon\n
\n
Things I did this evening
I've tried something along the lines of
Code:
while input != ESC
userInput
I've looked through Google, rewording it several times.
I've looked through my "The C Programming Language" book.
I've looked through the FAQ and forums here but so far found nothing.
Here's the line in context if it helps (ps. the code below runs with no errors):
Code:
#include <time.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
time_t current_time;
struct tm * time_info;
FILE *fp;
char timeString[16], fileName[20], entry[1000], *p; // space for "YYYY.mm.dd HHMM\0"
time(¤t_time);
time_info = localtime(¤t_time);
strftime(timeString, sizeof(timeString), "%Y.%m.%d %H%M", time_info); //define value of timeString
strftime(fileName, sizeof(fileName), "%Y.%m.%d.txt", time_info); // define value of fileName
printf("Diary entry for %s\n",timeString); // print variable timeString
printf("Entry: ");
fgets(entry, sizeof(entry), stdin);
fp=fopen(fileName, "a"); // filename = date&time
fprintf(fp, "%s\n\n%s\n\n\n", timeString, entry);
int fclose(FILE *);
return(0);
}