Question

Part 1 Write a program that reads a line of input and display the characters between...

Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters.

For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#!

1) Name your program stars.c.

2) Assume input is no more than 1000 characters.

3) String library functions are NOT allowed in this program.

4) To read a line of text, use the read_line function (the pointer version) in the lecture notes.

5) Include and call the search function. The search function expects s1 to point to a string containing the input as a string and stores the characters between the first two '*' to the string pointed by s2. If the input does not contain two '*', s2 should contain an empty string. An empty string is a valid string with no characters except the null character. The function returns 1 if the input contains two '*', and returns 0 otherwise.

int search (char *s1, char *s2);

6) The search function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function.

7) The main function should display the output

comments and steps would be helpful Thank

int read_line(char *str, int n)
{
int ch, i = 0;
while((ch = getchar()) != '\n')
{
if(i < n)
{
*str++ = ch;
i++;
}
}
*str = '\0';
return i;
}

Homework Answers

Answer #1

If it works please give me a like. It takes lot of effort to solve coding question.

Output and code screen shot are attached for your references.

Code:

------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main()
{
char str[1000];
int flag = 0;
int x = read_line(&str, 1000);
return 0;
}
int read_line(char *str, int n)
{
int ch, i = 0, flag = 0;
while((ch = getchar()) != '\n')
{
if(i < n)
{
if(flag == 1 && ch != 42)
{
printf("%c",ch);
}
if(ch == 42)
{
flag++;
}
*str++ = ch;
i++;
}
}
*str = '\0';
return i;
}

---------------------------------------------------------------------------------------------------

Code and output screenshots:

Know the answer?
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
Similar Questions
Write a program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex:...
Write a program that prompts the user to input a string and outputs the string in...
Write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use dynamic arrays to store the string.) my code below: /* Your code from Chapter 8, exercise 5 is below. Rewrite the following code to using dynamic arrays. */ #include <iostream> #include <cstring> #include <cctype> using namespace std; int main() { //char str[81]; //creating memory for str array of size 80 using dynamic memory allocation char *str = new char[80]; int len;...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Write an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a given string. Then write a simple main() function where you can repeatedly enter a string and then the num- ber of consonants is determined and printed on the screen (from the main() function). If the entered string is empty (it will contain only a ’\n’ then) the program should stop its execution. You can safely assume that the entered string will be not longer...
Write a function to check whether string s1 is a substring of string s2. The function...
Write a function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. For example, the function should return 2 if s1 is "to" and s2 is "October". If s1 is "andy" and s2 is "candy", then the function should return 1. The function prototype is as follows: int indexOf(const char *s1, const char *s2) Write a program to test the function.
C++ Part B: (String) Program Description: Write a word search program that searches an input data...
C++ Part B: (String) Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount) ; (15%)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT