Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(IN C WITH COMMENTS) \"USING STRINGS\" SF1747 Apps Downned n thing Analytical R

ID: 3818778 • Letter: #

Question

(IN C WITH COMMENTS) "USING STRINGS"

SF1747 Apps Downned n thing Analytical R we CIS plural Supply mom fly The plural araw kew 2 Q 2 uestion Write a funerinn: vnid rewrsetchar line char revpresiedy that takes data a line at a time and reverse e, e 1. Prompts usner to enter a lime and reads it from nput 2. Passes the string to function reverse 3. Prints out the reversed 4. Prompts the user to do another by typing "v or to quit the program by typing Sample output: birds and bees Do A lie: Hello W World Hello Do Another lyin)?n aay key

Explanation / Answer

code:

#include <stdio.h>
#include <string.h>

int str_len(char s[]) {
int i=0;

while(s[i]!='')
i++;

return i;  
}

void str_rev(char s[]) {
int i,j,len;
char ch;

j = len = str_len(s) - 1;
i = 0;

while(i < j) {
ch = s[j];
s[j] = s[i];
s[i] = ch;
i++;
j--;
}
}

int main (void) {
char sentence[] = "this is sample sentence";
char reverse[100] = "", t[50];
int i, j, n;


n = str_len(sentence);

for(i = n-1; i >= 0; --i) {

for(j = 0; i >= 0 && sentence[i] != ' '; --i,++j)
t[j] = sentence[i];

t[j] = '';

str_rev(t);
  
strcat(reverse,t);
strcat(reverse," ");
}

printf("orig - %s ", sentence);
printf("Reversed - %s ",reverse);

return 0;
}