Ciao ragazzi e buona pasqua.
Premetto che ho letto la documentazione di fgets ma non trovo ciò che fa al caso mio.
Ovvero:
Qui mi sembra parli solo dell'eventuale occorrenza della fine del file...ma come faccio a controllare che la funzione non vada in "buffer overflow" ,ovvero come faccio a controllare che il buffer sia sufficentemente capiente?On success, the function returns str.
If the end-of-file is encountered while attempting to read a character, the eof indicator is set (feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged).
If a read error occurs, the error indicator (ferror) is set and a null pointer is also returned (but the contents pointed by str may have changed).
Ad esempio:
Come condizione ho provato a metterci ferror(stdin) ma non funziona..anche perchè questo bit si setta solo se c'è stato un errore di lettura...e questo non è un errore di letturacodice:int main() { char parola[5]; do{ cout << "Inserisci la parola da testare "; fgets(parola,5,stdin); if(//Non so la condizione) cout << "Buffer overflow "; } while(non so la condizione);
Grazie delle risposte![]()

.
Rispondi quotando