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
Write a method named showChar. The method should accept two arguments: a reference to a String object and an integer. The intege
matrenka [14]

A complete program with the method ShowCar:

import java.util.Scanner; // header file

public class ShowChar

{

public static void main(String[] args)

{

String lnOfText;

int i;

Scanner input = new Scanner(System.in);

System.out.print("Enter a line of text:");

lnOfText = input.nextLine();

System.out.print(" Enter your index: ");

i = input.nextInt();

show_Char(lnOfText,i);

}

public static void show_Char(String str_a, int i)

{

System.out.print(str_a.charAt(i));

}

}

In this program, both the inputs ie. a sentence or line of text as well as the index position is obtained. A method is written to find the string at that particular position. Finally the method prints that character at the particular index.

5 0
3 years ago
Can you share a google Docx. with a person who has an Icloud Email?
stiks02 [169]

Answer:

Yes, all you do is click 'share' on the top right and then copy the link, then you would send the link to said to person that has a icloud email.

5 0
3 years ago
Knowledge management software helps companies preserve the knowledge gained through the use of information so that future users
V125BC [204]

Answer:True

Explanation:

Knowledge Management (KM) software is software that assists with the identification, creation, distribution, and organization of a company’s knowledge pool. KM software, at its best, gives a company a single, unified pool of information that is easily

(1) accessible

(2) discoverable

(3) updated

KM software is meant to make companies leaner, efficient, and more profitable. But a number of challenges exist which make that easier said than done. Let’s look at a few of the primary challenges that make KM software so important for businesses—but so difficult to get right.

8 0
3 years ago
Read 2 more answers
1. How does inertia affect a person who is not wearing a seatbelt during a collision?
Ivenika [448]
They could go flying out the window, getting seriously injured. This could also leave to death.
5 0
3 years ago
Read 2 more answers
what would you have to do to delete a document from your computer so that it could not possibly be read by anyone else?
Ket [755]

Answer:

Remove the doc using the trash button on it, bit if that doesn't work, just backspace the whole thing (an easier way to backspace it is to highlight everything you typed and hit backspace once).

7 0
2 years ago
Other questions:
  • I'll give brainlist to right answers
    7·1 answer
  • Create a test that prompts a user to enter a 5-digit PIN in the main procedure and then calls Validate PIN procedure to validate
    12·1 answer
  • Write a function (named n_pointed_star) to make the turtle draw an n-pointed star. The function should return nothing, and accep
    10·1 answer
  • What does media saturation mean?
    15·1 answer
  • In Windows Vista, the Run command can be found in which application?
    6·1 answer
  • An information system includes _____, which are programs that handle the input, manage the processing logic, and provide the req
    14·1 answer
  • Please check my answers! (Java)
    9·1 answer
  • Which of the following helps create a positive community?
    11·1 answer
  • Bradley is working on a program that uses different classes in specific relationships. Help him remember what these relationship
    14·1 answer
  • What type of software repairs or improves a larger application that is already installed on a system?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!