help in these problems
| soka2oo7 (10) | |||
| i want to know how to check that a data is interger or not ? & how to check that the file is empty & how to get the dimensions of a matrix in a file by using pointers or arrays. | |||
| SteakRider (110) | |||||
how to check that a data is interger or noti would use to know if it is integer ot not
how to check that the file is empty
| |||||
| SteakRider (110) | |||
| >>>how to check that a data is interger or not ? No matter what kind of data in the file, just read the file line by line to string, then Use what i wrote on the below. >>>how to check that the file is empty look at the previous reply >>>how to get the dimensions of a matrix in a file by using pointers or arrays first of all you should read the data, otherwise, you can not know anything about the data, after you read the data, the count elements, then you get the dimention of martix | |||
| soka2oo7 (10) | |||
| the checking if the dta is integer doesn't work & please explain line 3,4,5,6 | |||
| SteakRider (110) | |||
| |||
| rpgfan3233 (111) | |||
Line 3 should read
n = strlen(str);Forgot the semicolon, and you accidentally mistyped "strlen" as "sttlen". ^_^ For the integer bit, I don't understand how that would work since sscanf returns the number of items successfully read, not the number of characters... If it doesn't work, here is another option:
It is long, but it works! | |||
| cppman (2) | |||
| I think SteakRider is correct. "sscanf" returns the number of digits in the string. And if the number of digits are not equal to that of all the characters in the string, it means some other characters exist in the string, such as ".". In that case, the data represented by the string cannot be an integer. | |||
| rpgfan3233 (111) | |||||
| >"sscanf" returns the number of digits in the string. No, it doesn't. It returns the number of items successfully read from the string and stored in the specified variable(s):
Output:
11 1It returns the number of items successfully read from the string and stored in the variable(s) specified. If it reads 2 digits from the string "11.0" into a single integer, as it did in this example, then it returns the number of successful attempts, which in this case is 1. It doesn't return the number of digits that were successfully read. This holds true for char arrays (C-style strings) as well:
Output:
11.0 1 | |||||
This topic is archived - New replies not allowed.
