Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that asks the user for an input string and removes all space characters from it. The program then prints the resulting string

image text in transcribed

Write a program that asks the user for an input string and removes all space characters from it. The program then prints the resulting string without spaces a) (4 pt.) Write the full MIPS program and submit it in a file named q2.asm. b) (1 pt.) Run it on MARS and show the output of the simulation. Make sure to enter a string containing spaces to demonstrate the correct functionality of the algorithm. The following C code shows the proposed algorithm. The string is traversed with two indices, called old_index and new_index, where the latter always takes a value less or equal to the former. When a non-space character is found, the character at position old_index is copied to position new_index, and both indices are incremented. When a space is found, the current character is not copied, and only old_index is incremented. The algorithm stops when a null character is found. include int main // Read string char s[100]; printf ("Enter string:"; gets (s) // Remove spaces char c int old index = 0; int new index = 0; // Read character c = s [old index ]; // old position moves ahead old index++ /1 If it's a space, ignore if (c == ' ') continue; // Copy character s[new index] = c; // New position moves ahead new index++ while (c) Print result printf("New string: %s ", s); Write a program that asks the user for an input string and removes all space characters from it. The program then prints the resulting string without spaces a) (4 pt.) Write the full MIPS program and submit it in a file named q2.asm. b) (1 pt.) Run it on MARS and show the output of the simulation. Make sure to enter a string containing spaces to demonstrate the correct functionality of the algorithm. The following C code shows the proposed algorithm. The string is traversed with two indices, called old_index and new_index, where the latter always takes a value less or equal to the former. When a non-space character is found, the character at position old_index is copied to position new_index, and both indices are incremented. When a space is found, the current character is not copied, and only old_index is incremented. The algorithm stops when a null character is found. include int main // Read string char s[100]; printf ("Enter string:"; gets (s) // Remove spaces char c int old index = 0; int new index = 0; // Read character c = s [old index ]; // old position moves ahead old index++ /1 If it's a space, ignore if (c == ' ') continue; // Copy character s[new index] = c; // New position moves ahead new index++ while (c) Print result printf("New string: %s ", s)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

design a simple performance appraisal system

Answered: 1 week ago