I have read that is unsafe read from stdin like I do:
[code]
char buffer[40];
fscanf(stdin, "%s", buffer);
[\code]
Anyone know a safe way to do this? I am a noob linux user.
This is a discussion on C\linux - safe reading from input within the C++ Programming forums, part of the General Programming Boards category; I have read that is unsafe read from stdin like I do: [code] char buffer[40]; fscanf(stdin, "%s", buffer); [\code] Anyone ...
I have read that is unsafe read from stdin like I do:
[code]
char buffer[40];
fscanf(stdin, "%s", buffer);
[\code]
Anyone know a safe way to do this? I am a noob linux user.
Actually you can do it in two ways:
First you can use fgets, read :
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
But if you are a alternative guy, you can use the fscanf like this:
Where LENGTH is macro specifing the length of the stringCode:char buffer[LENGTH+1]; //using LENGTH+1 to store de '\n' fscanf(stdin,"%LENGTHs",buffer);