D
D
Dred Wolf2020-12-02 19:36:31
C++ / C#
Dred Wolf, 2020-12-02 19:36:31

How to find the number of numbers in a txt file?

How can I count the number of numbers in a txt file in C? The numbers are real and separated by spaces, for example: 3.12 5.44 5.55 8.90

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2020-12-02
@CityCat4

Took the file size (man readdir)
Requested memory for reading the file by file size (man calloc)
Opened the file (man open)
Read it (man read)
Closed the file (man close)
Counted the number of spaces in the buffer, checked that after the last one there is a number (eliminate the situation when there is a space after the last number), if so,
added
one
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question