Question

Can anyone help me write a C function that goes through an input string and insert...

Can anyone help me write a C function that goes through an input string and insert spaces(" ")infront and after "<",">","|"?

For example: if my input string is: HELLO<WO|RLD>!, the output of the function will be a array like: HELLO < WO | RLD > !

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// b has the output string
change(char* a)
{
int ind=0,i;
char b[1000];
  
// as long as a has characters
while(*a)
{
// if the character is required symbol
if(*a == '<' || *a == '>' || *a == '|')
{
// adding spaces before and after
b[ind++] = ' ';
b[ind++] = *a;
b[ind++] = ' ';
}
else
{
b[ind++] = *a;
}
*a++;
ind++;
}
  
// printing output
for(i=0;i<ind;i++)
{
printf("%c",b[i]);
}
}

main()
{
// sample run
change("HELLO<WO|RLD>!");
}

Sample Output

HELLO < WO | RLD > ! 
Add a comment
Know the answer?
Add Answer to:
Can anyone help me write a C function that goes through an input string and insert...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can anyone please help me to write a recursive ( must in recursive function) function in...

    can anyone please help me to write a recursive ( must in recursive function) function in c++ to print the asterisk pattern in the screenshot below. thanks as this:

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • Can anyone help me to solve this problem? Thanks in advance Assignment 6 Strings Write a...

    Can anyone help me to solve this problem? Thanks in advance Assignment 6 Strings Write a program which makes Caesar encryption. Caesar encryption is based on circular shifting of the letters with a given amount. Your program will encrypt the input and it will shift the letters by the given amount (if it passes z, it will continue from a), it will not change spaces (" "). You can assume that no other characters will be entered.

  • For my assignment, I'm trying to write Insert function like C++ insert. My function should insert...

    For my assignment, I'm trying to write Insert function like C++ insert. My function should insert one string into other string at a certain position. Inputs: destination : Be my friend today source : good position : 6 Output: Be my good friend today How should I make room in the middle of the string ? This is my code so far. Insert PROC PROC uses edi esi ebx ecx, destination:DWORD , source:DWORD, position:DWORD    mov esi,destination ;add esi address...

  • CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC. PLEASE INCLUDE...

    CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC. PLEASE INCLUDE CORRECT SYNTAX...MUST BE IN PYTHON 3 AND PASS THE TEST Write a function analyze_text that receives a string as input. Your function should count the number of alphabetic characters (a through z, or A through Z) in the text and also keep track of how many are the letter 'e' (upper or lowercase). Your function should return an analysis of the text in the...

  • Write a program that can remove spaces from an input string, find the indexes of a...

    Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...

  • Can anyone help me with my C hw? Exercise 3 You will write a new program...

    Can anyone help me with my C hw? Exercise 3 You will write a new program that combines dynamically allocating an array and saving that array to a file. These are the tasks your program must perform Open an output file named "data.txt" and prepare it for writing in text mode o If the file handle is NULL, quit the program o By default, it is created and stored in the same directory as your source code file Prompt the...

  • Can someone help me with these C program problems? Thanks 1. Write a C program that...

    Can someone help me with these C program problems? Thanks 1. Write a C program that creates two arrays of integers, one on the stack and one on the heap. You will loop through these arrays and populate them with values (any value is fine). You will then loop through these arrays again and print each value. Your output should look something like “Value in index 1 is 100 from stack array and 100 from heap array.” Do not forget...

  • C programming Write a function that goes through all elements of an array of size n,...

    C programming Write a function that goes through all elements of an array of size n, and output the minimum and maximum values using pointers. Since C functions can only return one value, you must use pointers to output the minimum and maximum values from the function. You are not expected to print the values on the screen. Note: you will be assessed on the functionality and the coding style.

  • C++ Demonstrate an understanding of array processing. Write a function that accepts the name of a...

    C++ Demonstrate an understanding of array processing. Write a function that accepts the name of a file (by asking the user), an array of strings, and the size of the array. Display each character of each string vertically to the file. For example, if the array is called with an array of 3 strings “hello”, “abc”, “bye”, the output will be: h e l l o …. y e Test the function with a string declaration of: string name[] =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT