Write a program named as reverse.c that reads a message, then prints the reversa
ID: 3774751 • Letter: W
Question
Write a program named as reverse.c that reads a message, then prints the reversal of the message. The output the program should look like this: Enter a message: Don't get road, get even. Reversal is: .neve teq, dam teq t 'noD Revise the program in Part I to use a pointer instead of an integer to keep track of the current position in the array. Name the new C program as reverseP.c. Put the source code of reverse.c and reverseP.c in your answer sheet. In your answer sheet, please also attach screenshots of the outputs Upload your file reverse.c and reverseP.c to iCollege.Explanation / Answer
#include<stdio.h>
int main() {
int i = 0;
char c, message[1000] = "";
printf("Enter a message: ");
while(1){
c = (char)getchar();
if(c == ' ') break;
message[i++] = c;
}
i--;
printf("Reversal is : ");
while(i>=0) {
printf("%c",message[i--]);
}
return(0);
}
reverseP.c
#include<stdio.h>
int main() {
char *p;
char c, message[1000] = "";
printf("Enter a message: ");
p = message;
while(1) {
c = (char)getchar();
if(c == ' ') break;
*p = c;
p++;
}
printf("Reversal is : ");
while((p - message) >= 0) {
p--;
printf("%c",*p);
}
return(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.