We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
As the text says, it is just a warning. It is good to always check warnings - and when writing production code, you should probably make sure that there are no warnings left. However, a warning is not an error - the compiler just compiles fine.
Warnings indicate positions in your code that could lead to possible runtime errors, i.e. errors that occur when the program encounters an unexpected situation (different to syntax errors, where you as a programmer made mistake). Such an unexpected situation could be, that even though you asked for a path (via scanf) the user does not provide one. Now later in your code when you want to write or read from that path, your programm is going to crash.
As many have mentioned already, with the return value of scanf you can see if everything went as expected - normally you would save this value and check whether ther was an error or not - so that if something happend that should not, you could ask the user to repeat the input.
For these exercises however, this is not needed, so it's safe to just ignore the error. However, if it makes you feel better just do a int ret = scanf(...), and the error should disappear. Or if you are a bit more advanced: If you take a look here, it will tell you that the error code is saved under the constant EOF, so you could do something like this:
if(scanf("%d", &n) == EOF) {
printf("Error occured while reading form STDIN");
}
But don't let it bother you if this is still to advanced.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Basic Data Types
You are viewing a single comment's thread. Return to all comments →
As the text says, it is just a warning. It is good to always check warnings - and when writing production code, you should probably make sure that there are no warnings left. However, a warning is not an error - the compiler just compiles fine.
Warnings indicate positions in your code that could lead to possible runtime errors, i.e. errors that occur when the program encounters an unexpected situation (different to syntax errors, where you as a programmer made mistake). Such an unexpected situation could be, that even though you asked for a path (via scanf) the user does not provide one. Now later in your code when you want to write or read from that path, your programm is going to crash.
As many have mentioned already, with the return value of scanf you can see if everything went as expected - normally you would save this value and check whether ther was an error or not - so that if something happend that should not, you could ask the user to repeat the input.
For these exercises however, this is not needed, so it's safe to just ignore the error. However, if it makes you feel better just do a
int ret = scanf(...)
, and the error should disappear. Or if you are a bit more advanced: If you take a look here, it will tell you that the error code is saved under the constantEOF
, so you could do something like this:But don't let it bother you if this is still to advanced.