A
A
Anvario02022-01-15 20:00:27
C++ / C#
Anvario0, 2022-01-15 20:00:27

How to write a program in C that extracts numbers from strings?

How to write a program in C that looks for a number and if it stumbles upon it, then looks for its largest digit, displays it on the screen and continues the search? For example, the string "aaa010101bbb343ccc" - the program should first find the number 010101 and display its largest digit - 1, then the program should find the number 343 and find its largest digit - 4.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2022-01-15
@gbg

You can start, for example, by learning to stomp on the line and select only numbers from it

W
Wataru, 2022-01-15
@wataru

Write a function that, starting at a given index, selects a number in a string and returns the index of the end of the number. This function consists of a stupidly single while that checks for not a character or the end of a string is the current character.
The program itself follows the line, if it sees that the current character is a digit, then it launches the function above. Then displays from the current to the found character, then shifts the current index to the end of the number. Better to do while. Inside, you either increment the index by 1 if the current character is not a digit, or shift it to the end of the found number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question