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
A key or combination of keys that complete an action more efficiently than using the mouse is called a(n) keyboard shortcut.
andreev551 [17]
The answer to your question is true
6 0
3 years ago
What term describes a wireless network topology in which access points work as peer devices on the same network?
kumpel [21]
Mesh WLAN wireless mesh network WMN describes a wireless network topology in  access points work as peer devices on the same network.
<span />
7 0
3 years ago
Write a method called compress that takes a string as input, compresses it using rle, and returns the compressed string. case ma
MaRussiya [10]
<span>public static String compress (String original) { StringBuilder compressed = new StringBuilder(); char letter = 0; int count = 1; for (int i = 0; i < original.length(); i++) { if (letter == original.charAt(i)) { count = count + 1; } else { compressed = count !=1 ? compressed.append(count) : compressed; compressed.append(letter); letter = original.charAt(i); count = 1; } } compressed = count !=1 ? compressed.append(count) : compressed; compressed.append(letter); return compressed.toString(); }</span>
5 0
4 years ago
Using symbols in a file name is a good idea.<br><br> True<br> False
zavuch27 [327]
False. File names should only contain letters, underscores, periods, and dashes.
4 0
3 years ago
Read 2 more answers
What are some ways to manage stress? Check all that apply.
Romashka-Z-Leto [24]
Exercise Breathe deeply Take breaks Study at night
7 0
3 years ago
Read 3 more answers
Other questions:
  • A usability study compares the number of page visits on a web site. Half of the participants saw Version A of the home page. The
    13·1 answer
  • Why is it a good idea to save work in the cloud
    10·2 answers
  • What is a tag in an HTML document?
    5·1 answer
  • What is a graphical representation of a real person in a virtual community called?
    5·1 answer
  • The popularity of blogging is an example of _____. the public producing the media the public regulating the media both of the ab
    15·2 answers
  • Can you get in trouble for copying something you thought you were allowed too reddit?
    9·1 answer
  • Explain the procedure you will undertake to create a new partition​
    11·1 answer
  • "queries are questions", true or false?
    8·2 answers
  • which kind of system software tells the computer how to communicate with peripherals, such as a printer or scanner?
    7·1 answer
  • If a packet gets "sucked down a black hole" (figuratively speaking) and is not received by its sender, and no message is sent ba
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!