Hi,
I'm writing a basic line editor program, I'm trying to get my insert function working, but for some reason when storing my lines it only correctly does so for the first line of input and then for proceeding lines is missing the first character in that line.
For eg:
OUTPUT:
? i
Hello
World
.
? p
Hello
orld
?
SHOULD BE:
? i
Hello
World
.
? p
Hello
World
?
I believe it is an issue with having the fgetc within the following loop because testing my program with the single fgets it works fine, but I need someway to account for a "." in stdin to break the insertion of text.
If someone could help me, that would be greatly appreciated.
Code:
while (1) {
char c = getCmd();
if (c == 'x') {
printf("Forced exit, changes not saved\n");
break;
} else if (c == 'h') {
//call printhelpList
printhelpList();
} else if (c == 'i') {
while (fgets(line, LINELENGTH, stdin)) {
lines[numLines] = strdup(line);
numLines++;
if (fgetc(stdin) == '.') {
if (fgetc(stdin) == '\n') {
break;
}
}
}
} else if (c == 'p') {
//call printLines
printLines(lines, numLines);
}