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
Darina [25.2K]
3 years ago
8

In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '

OXOXO' and whenever the character 'N' is put into the command line, a character from the existing string would be removed. So if the user inputs the string 'oNoN' into the command line, the new string would be 'OXO'.

Computers and Technology
1 answer:
s344n2d4d5 [400]3 years ago
6 0

Answer:

// here is code in C.

#include <stdio.h>

// main function which take input from command line

int main(int argc, char** argv) {

               // variables

               int char_count = 0, i=0;

               // string as char array

               char inp_str[100] = "OXOXO";

               //count  total number of 'N's in command line argument

               while(argv[1][i++] != '\0')

               {

                 if(argv[1][i]=='N')

                     char_count++;

               }

               // find the length string

               int l = 0;

               while(inp_str[l] != '\0')

                               l++;

               //reduce length of the string

               l = l - char_count;

               //set null char at index "l" so it will  removes character after index "l"

               inp_str[l] = '\0';

               printf("%s\n", inp_str);

               return 0;

}

Explanation:

Create a string as character array and initialize it with "OXOXO".After that count the number of "N" which come from the command line argument.Then find the length of input string.Reduce the length of string and set "null" at index "l" in the string.Then print the string.

Output:

OXO

<u>Command line argument:</u>

You might be interested in
What is true about content based filtering
AleksAgata [21]

Answer: provide more info

Explanation:

8 0
3 years ago
Mr. Andrews, the lead programmer for the game New Horizons, hires independent testers to check the game for stability and perfor
NikAS [45]
I think “D”, did I help?
5 0
3 years ago
Read 2 more answers
Activities provided for the satisfaction of others and consumed at the time of purchase<br> are…
Natasha2012 [34]
The answer is services
6 0
3 years ago
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
natka813 [3]

Answer:

tyhgfrd

Explanation:

8 0
3 years ago
Computer data that is suitable for text​
TiliK225 [7]

<em>Answer:</em>

<em>Answer:Data Types. Computer systems work with different types of digital data. In the early days of computing, data consisted primarily of text and ...</em>

3 0
3 years ago
Other questions:
  • What kind of memory modules include registers between the system’s memory controller and the module’s memory chips, registers th
    7·2 answers
  • A ____ client locates all or most of the processing logic on the server.
    11·1 answer
  • An email can lead to miscommunication because:
    6·2 answers
  • After compiling source code, which command still needs to be run in order to copy the newly compiled binaries into a directory l
    5·1 answer
  • HELPPPP PLEASE HURRY
    15·1 answer
  • Design a class called NumDays. The class’s purpose is to store a value that represents a number of work hours and convert it to
    12·1 answer
  • Which of the following questions will most likely be answered by displaying data on a line graph?
    11·1 answer
  • At the beginning of Section 5.2, it is stated that multiprogramming and multiprocessing present the same problems, with respect
    8·1 answer
  • Im learning about AI in my class and I'm confused about these two questions
    9·2 answers
  • All HTML5 webpages must begin with the HTML element _____.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!