I am loading matrix from file and here comes the question, how to treat if there will be fault in loading file if there will be letter instead of number? I am especially asking – how to determine, that I loaded letter?
Thx
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the input read by
fscanf()does not match the expected type (as determined by the conversion specifier), this will be reported by the return value offscanf()(which is equal to the number of coversion specifiers successfully read).More generally speaking, the whole
scanf()family of functions is primarily aimed at reading whitespace-separated, trivial data. Usually it is more easy and reliable to read in a complete line (usingfgets()), and then doing the parsing internally. (strtol()andstrtod()can be of help here, butstrtok()should be used with care, especially in a multithreaded environment.)