Question: Write a C program using the code below: TEMPLATE: #include #include #include #include #define TRUE 1 #define FALSE 0 #define BUFSIZE 80 // Reverse str,

Write a C program using the code below: Write a C program using the code below: TEMPLATE: #include #include #include

TEMPLATE:

#include

#include

#include

#include

#define TRUE 1

#define FALSE 0

#define BUFSIZE 80

// Reverse str, which has len characters.

// str may not have an ending NULL, but you already have len.

// suppose you have 10 chars to reverse:

// you swap 0 and 9, 1 and 8, 2 and 7 and so on.

void str_reverse(char str[], int len)

{

// TODO

}

int main()

{

char ch = 0;

char buf[BUFSIZE];

int i = 0;

int inWord = FALSE;

while ((ch = getchar()) != EOF) {

// isspace() may return non-zero values that is not 1.

// So be careful.

int sp = isspace(ch);

// depending on the value of ch and inWord.

// You have four cases to handle.

// TODO

if (sp) { // if ch is a space

} else {

}

}

// What if the file does not end with a space?

// TODO

}

Martians are rumored to use a bizarre system where words are read backward (right to left) even though the text as a whole is read left to right. Is written English generally understandable if words were presented in that way? To experiment, write a program that reads text from the standard input and writes to the standard output the text with its words reversed. For example, running the program with this paragraph given as input should produce as output: snaitraM era deromur ot esu a errazib metsys erehw sdrow era daer drawkcab thgir( ot )tfel neve hguoht eht txet sa a elohw si daer tfel ot .thgir sI nettirw hsilgnE yllareneg elbadnatsrednu fi sdrow erew detneserp ni taht ?yaw oT ,tnemirepxe etirw a margorp taht sdaer txet morf eht dradnats tupni dna setirw ot eht dradnats tuptuo eht txet htiw sti sdrow .desrever roF ,elpmaxe gninnur eht margorp htiw siht hpargarap nevig sa tupni dluohs ecudorp sa :tuptuo Note how punctuation is considered to be part of the word if there is no white-space separating it from the end of the preceding word. White-space characters in the input should be copied to the output Use command line redirection from a file containing some English text to test your program. For example, $echo "ab defg" > a.txt $./reverseWord a.txt $./reverseWord

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!