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;
}
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:
Get Answers For Free
Most questions answered within 1 hours.