I have an issue here were I can't find a way to stop fgets() to read from stdin after I paste my input in it. I want it to read what I pasted and stop after (it can be different length). Now it is waiting for another input.
void readMatrix(char (*charM)[40]) {
char charT[42] = {0};
int count = 0;
while (fgets(charT, 42, stdin) != NULL) {
for (int i = 0; i < 40; i++){
if (charT[i] == 0 || charT[0] == '\n' ) {
printf("Erreur: Caractère `EOF` inattendu, attendu `H`, `X`
ou `.`.");
exit(0);
}
if(charT[i] != '.' && charT[i] != 'H' && charT[i] != 'X') {
printf("Erreur: Caractère `%c` inattendu, attendu `H`, `X`
ou `.`.", charT[i]);
exit(0);
}
charM[count][i] = charT[i];
}
count++;
if (count == 20) break;
}
}
Thanks!