Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
Plz use c programming to complete the coding and plz don't use libraries other than the one written
Write two functions, first() and last (), described as follows:
• the function first () takes a strings and a character c as arguments and returns a pointer
to the first occurrence of the character c in the string s. That is, if s = "A string to
be searched" and c = 'e', then the function first() returns a character pointer to
the 'e' in the word "be". If the character does not occur in the string s, then the value
NULL is returned.
• the function last () takes a string s and a character c as arguments and returns a pointer
to the last occurrence of the character c in the string s. That is, if s = "A string to
be searched" and c = 'e', then the function last() returns a character pointer to the
'e' just before the 'd' in the last word. Again, if the character does not occur in the
string, then the NULL pointer is returned.
Write a main program which defines a string, str, which contains the sentence “A string to be
searched". Your program should then prompt the user for the character to search for, c. The
functions first() and last () are then called with str and c as arguments and the resulting
strings (starting at the returned pointers) are printed to an output file. For example, if you
type in the letter 's' as the character to search for, your program should print out:
Original string :
A string to be searched
First occurrence of 's' starts the string:
string to be searched
Last occurrence of 's' starts the string :
searched
Test your program using the characters 'r', 'e' and 'q'. Note that the last should give the
error message: Character 'q' not found.
expand button
Transcribed Image Text:Write two functions, first() and last (), described as follows: • the function first () takes a strings and a character c as arguments and returns a pointer to the first occurrence of the character c in the string s. That is, if s = "A string to be searched" and c = 'e', then the function first() returns a character pointer to the 'e' in the word "be". If the character does not occur in the string s, then the value NULL is returned. • the function last () takes a string s and a character c as arguments and returns a pointer to the last occurrence of the character c in the string s. That is, if s = "A string to be searched" and c = 'e', then the function last() returns a character pointer to the 'e' just before the 'd' in the last word. Again, if the character does not occur in the string, then the NULL pointer is returned. Write a main program which defines a string, str, which contains the sentence “A string to be searched". Your program should then prompt the user for the character to search for, c. The functions first() and last () are then called with str and c as arguments and the resulting strings (starting at the returned pointers) are printed to an output file. For example, if you type in the letter 's' as the character to search for, your program should print out: Original string : A string to be searched First occurrence of 's' starts the string: string to be searched Last occurrence of 's' starts the string : searched Test your program using the characters 'r', 'e' and 'q'. Note that the last should give the error message: Character 'q' not found.
#include<stdio.h>
char* first (char* s, char c);
int main(void) {
char* f
char* i;
}
f=first(s,c);
if (f==NULL) {
}else{
fprintf(fout, "%s", f);
}
return 0;
}
char first (char* s, char c) {
char* answer=NULL;
for (i-e;s[i]!= '\0';i++){
if(s[i]==c){
answer=&s[i];
break;
return answer;
expand button
Transcribed Image Text:#include<stdio.h> char* first (char* s, char c); int main(void) { char* f char* i; } f=first(s,c); if (f==NULL) { }else{ fprintf(fout, "%s", f); } return 0; } char first (char* s, char c) { char* answer=NULL; for (i-e;s[i]!= '\0';i++){ if(s[i]==c){ answer=&s[i]; break; return answer;
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education