subject
Chemistry, 21.04.2020 21:34 bermudezs732

Write a C program that implements and tests the three C functions described in problems 5, 6 and 7 on page 231 of the text. Here are the prototypes:

// find second string in first

// return index where string starts or -1 if not found

int findString(char *, char *);

// remove specified number of characters starting at

// a specified index.

// first int is starting index, second is count

// if failure, do nothing

void removeString(char *, int, int);

// insert the second string into the first starting

// at the specified index

// if failure, do nothing

void insertString(char *, char *, int);

Problem 5 from page 231 stats: Write a function called findString() to determine if one character string exists inside another string. The first argument to the function should be the character string that is to be searched adn the second argument is the string you are interested in finding. If the function finds the specified string, have it return the location in the source string where the string was found. If the function does not find the string, have it return -1.

Problem 6: Write a function called removeString() to remove a specified number of characters from a character string. The function should take three arguments: The source string, the starting index number in the source string, and the number of characters to remove.

Problem 7: Write a function called insertString() to insert one character string into another string. The arguments to the function should consist of the source string, the string to be inserted, and the position in the source string where the string is to be inserted.

Specification

1. For this project, the purpose of "main" is to simply test the three functions. Do not have the user supply data to main.

2. One additional requirement beyond what is stated in the text is that square brackets "[ ]" are not allowed in any of the three functions. In other words, use pointers to access the character strings rather than array notation.

NOTE: Square brackets are fine in "main".

3. Do not use any of the (string. h) library functions within your functions. Note, you may use those functions in "main" if you like.

4. Use the exact prototypes provided above.

5. You may have as many additional functions as you like. You are not limited to these three. (these are often called helper functions or utility functions)

THE TESTER MAIN THAT WAS GIVEN IS

int main()
{
//find
printf("Found hat at %i\n", findString("chatterbox", "hat"));
printf("Found att at %i\n", findString("chatterbox", "att"));
printf("Found box at %i\n", findString("chatterbox", "box"));
printf("Found boxx at %i\n", findString("chatterbox", "boxx"));

//remove
char str3[20] = "chatterbox";
removeString(str3, 9, 1);
printf("\nAfter remove 1 = %s\n", str3);

char str4[20] = "chatterbox";
removeString(str4, 4, 5);
printf("After remove 2 = %s\n", str4);

char str5[20] = "chatterbox";
removeString(str5, 0, 7);
printf("After remove 3 = %s\n", str5);

//insert
char str8[20] = "the wrong son";

insertString(str8, "per", 14);
printf("\nAfter insert 1 = %s\n", str8);

insertString(str8, "per", 10 );
printf("After insert 2 = %s\n", str8);

insertString(str8, "You are ", 0);
printf("After insert 3 = %s\n\n", str8);
return 0;
}

ansver
Answers: 2

Another question on Chemistry

question
Chemistry, 22.06.2019 06:30
What is the polyatamic ion of borate
Answers: 1
question
Chemistry, 22.06.2019 07:30
According to the vsepr theory what is the shape of a molecule that has a central atom valence three other items with no lone pairs of electrons
Answers: 1
question
Chemistry, 22.06.2019 08:00
This classification of drug typically changes the brain's chemistry and reduces its ability to create its own endorphins.
Answers: 1
question
Chemistry, 22.06.2019 11:00
Ais a mountain created from eruptions of lava, ash, rocks, and hot gases.
Answers: 1
You know the right answer?
Write a C program that implements and tests the three C functions described in problems 5, 6 and 7 o...
Questions
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
English, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
History, 15.09.2020 01:01
question
History, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
History, 15.09.2020 01:01
Questions on the website: 13722360