I have a text file that contains numeric data. And after I write the fscanf function (fp, "% d", & mas [0] [0]). When outputting in printf, I get instead of the numeric value of the character for example '1' (after all, as I understand everything is stored in a text file, the number is 1.) How does this happen?
- It is not clear what exactly you want to display: a number or a character? If you read the number 1 using the% d format specifier, this number will be displayed. - Vlad from Moscow
|
1 answer
The fscanf
function is a formatted input function. The %d
format fscanf
in fscanf
just says to her: read all consecutive characters from a file as long as they match the integer format
[пробельные символы][+/-](цифра)(цифра)...(цифра)
then convert them to the appropriate integer value of type int
and write it into an argument.
- that is, specifying the format specifier% d, the characters '+', '-', '1', '2', etc. will be regarded as numbers 1,2 and so on.? - Yaroslav
- @Yaroslav: Symbols
1
,2
, etc. will be regarded as string numbers. When it is found where the entry of the number ends, it will be converted to an integer type. - AnT - I understood everything, thank you. - Yaroslav
|