Complete this program by writing the function strip_q_marks that takes a single
ID: 3587916 • Letter: C
Question
Complete this program by writing the function strip_q_marks that takes a single string and returns an integer. The function should modify the string to remove any trailing question marks and return the number of question marks that were removed. Examples original sentence modified sentence return value "Hello? World?7?" "What..?" "Apples?..7 "Coffee" "Hello? World" "What.." "Apples?.." "Coffee" k/ // Write the function strip_q_marks here int main(int argc, char xkargv) != 2) if(argc { fprintf (stderr, "Usage: strip message ") exit(1); int result = strip-a_marks (argv [1]); printf("%s %d", argv [1], result); return 0;Explanation / Answer
//main.c
#include <stdio.h>
#include <string.h>
int strip_q_marks(char *sentence);
int main(int argc, char **argv) {
int result = strip_q_marks(argv[1]);
printf("%s %d", argv[1], result);
return 0;
}
int strip_q_marks(char *sentence){
int len;
int result = 0;
for (len = strlen(*sentence); len>0 ;len--){
if(sentence[len] == '?' && sentence[len+1] == ''){
result ++;
sentence[len] = '';
}
}
return result;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.