1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
saw5 [17]
3 years ago
6

Write a C program that reads a string containing text and nonnegative numbers from the user and prints out the numbers contained

in the string in separate lines. For example, if the input is: The year has 365 days and the day has 12 hours Then the output will be: 365 12
Computers and Technology
1 answer:
Alex_Xolod [135]3 years ago
6 0

Here is the code in C.

#include <stdio.h>

#include <string.h>

//main function

void main()

{

// character array to store the string

char str[1000];

int len,i,j;

char c,ch;

printf("Please Enter a string: ");

 // read the string

gets(str);

// find the length of input string

len = strlen(str);

for(i=0;i<len;i++)

 {

      c=str[i];

       // if any character of string is digit then it will check

       // until it finds the next non-digit character

     if(c>='0' && c<='9')

     {

         for(j=i;j<len;j++)

         {

             ch=str[j];

             if(ch>='0' && ch<='9')

              //print the number in the string

             printf("%c",str[j]);

             else

             {

                 printf(" ");

                 i=j;

                 break;

             }

         }

     }

 }

}

Explanation:

First it ask user to input a string and store that string into character array.Then travers the array and find first digit character.If a digit is found then print that digit.After that in the inner for loop, check next character is digit or not, if a digit meets then print that digit.Repeat this until the next non-digit character founds.When a non-digit character meets print a space and update the value of "i" and break the inner loop.It will again check the same from the ith index in the character array.

Output:

Please Enter a string: The year has 365 days and the day has 12 hours

365 12

You might be interested in
Can the redirection shell metacharacter be used to redirect between a command and another command?
Maksim231197 [3]
The answer is NO it cannot.
5 0
4 years ago
Why the computer is known as versatile and diligent device ? explain.<br>​
Scrat [10]

Answer:

Computer is called versatile and diligent device because it is used in almost all the fields for various purposes and it can perform the task repeatedly without loosing its speed and accuracy for long time.

5 0
2 years ago
How to make your nest learning thermostat stop doing something
k0ka [10]

Answer:

You could unplug it? LOL

and get a different thermostat.

Explanation:

Could you mark this answer as brainiest?

Thanks! :)

4 0
3 years ago
Hey I don’t have a question I’m just testing something on this app
Dafna1 [17]

Answer:

hahaha

Explanation:

4 0
3 years ago
Read 2 more answers
Terry is having a problem with his computer screen. He said the screen looks distorted. When you go to check his monitor, you no
andreyandreev [35.5K]

Answer:

B. Computer's resolution has been set too low

Explanation:

A. Font size has been set too high.

B. Computer’s resolution has been set too low.

C. Refresh rate of the video card is out of sync with the monitor’s refresh rate.

D. ClearType setting is enabled.

From the given options; if the font size has been set too high, the effect is on the texts and not icons. If the video card is out of sync there will be little or no display at all.

So, the correct option is Computer's resolution has been set too low.

3 0
3 years ago
Other questions:
  • If you have long column labels with columns so wide that they affect the readability of a worksheet, you should first
    15·2 answers
  • Technician A says that if the coefficient of friction is too low, the brakes will grab.
    12·1 answer
  • I really love my voice when not recorded. Now when I record my voice, I feel like its high pitched and horrible. Do I really sou
    11·1 answer
  • Need help ppplllleeeassse<br><br> Hhheeelllppp
    15·2 answers
  • Ben is writing web page content on a newly launched gaming gadget. He has to use hyperlinks to help visitors navigate to web pag
    11·1 answer
  • Write a modular program that accepts up to 20 integer test scores in the range of 0 to 100 from the user and stores them in an a
    9·1 answer
  • A message can be...........<br>differently by different people.​
    8·1 answer
  • WHAT IS THE LOCATION OF “A”. ON THE GRID?
    15·2 answers
  • 1. In platform construction, wall-framing members include sole plates,
    15·2 answers
  • Given that the input A is false, the input B is false, and the input C is true, what is the resulting value of the output?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!