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
Samantha was calculating a mathematical formula on an electronic spreadsheet. She used multiple values to recalculate the formul
Bezzdna [24]
<span>Random access memory. This problem requires you to know what the different types of memory are and their relative advantages and disadvantages. Let's look at them and see why 3 are wrong and one is correct. read-only memory: Otherwise known as ROM, this type of memory stores code that can't be over written. Used frequently for constant lookup values and boot code. Since it can't be written to by normal programs, it can't hold temporary values for Samantha. So this is the wrong choice. random-access memory: Otherwise known as RAM, this type of memory is used to store temporary values and program code. It is quite fast to access and most the immediately required variables and program code is stored here. It can both be written to and read from. This is the correct answer. hard disk: This is permanent long term readable and writable memory. It will retain its contents even while powered off. But accessing it is slow. Where the contents of RAM can be accessed in nanoseconds, hard disk takes milliseconds to seconds to access (millions to billions of times slower than RAM). Because it's slow, this is not the correct answer. But it's likely that Samantha will save her spreadsheet to hard disk when she's finished working with it so she can retrieve the spreadsheet later to work on again. compact disk: This is sort of the ROM equivalent to the hard disk. The data stored on a compact disk can not be over written. One way of describing the storage on a compact disk is "Write Once, Read many times". In most cases it's even slower than the hard disk. But can be useful for archiving information or making backups of the data on your computer.</span>
5 0
3 years ago
Read 2 more answers
What Is The First Computer Brought In Nepal ? <br>​
tiny-mole [99]

Answer:

I don't know,,,(((:lol

8 0
2 years ago
why does planets orbit the sun? asap i give brainlist i know it on that subject i dont know what else goes with it
Fynjy0 [20]

Answer:

Anyway, the basic reason why the planets revolve around, or orbit, the Sun, is that the gravity of the Sun keeps them in their orbits. Just as the Moon orbits the Earth because of the pull of Earth's gravity, the Earth orbits the Sun because of the pull of the Sun's gravity.

Explanation:

7 0
2 years ago
When was kale discovered?
anyanavicka [17]
Kale was discoverd just 2 years ago ........
8 0
3 years ago
50 POINTS How do you express yourself and your creativity through computer science?
Igoryamba

Answer:

1. I express myself through the designing, development and analysis of software and hardware used to solve problems in a variety of business, scientific and social contexts.

2. support the development of general reasoning, problem-solving and communication skills.

3. Through avoiding in repetious tasks and simplifying such works.

3 0
2 years ago
Other questions:
  • Directions Use your imagination and a word processor to write a business letter with two to three paragraphs. Your business lett
    5·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    9·1 answer
  • To expand the interface within CengageNOWv2, you need to click on the:_______.
    15·1 answer
  • Analytical CRM systems are the input for operational CRM systems.<br><br> True<br><br> False
    11·1 answer
  • What is human data,
    8·1 answer
  • Describe an energy problem a city in 2050 will face
    6·1 answer
  • Plssssssssssssss help quick
    8·1 answer
  • 6.16 LAB: Find largest number (EO) Write a method, findMax(), that repeatedly reads in integers until a negative integer is read
    9·1 answer
  • Write a method that returns a String that is just the first and last character of the given string Your return value should be o
    8·1 answer
  • • Do you think documentaries are best delivered in media such as films or documentary?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!