You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
620 B
39 lines
620 B
4 years ago
|
/*
|
||
|
* pr_12.c
|
||
|
*
|
||
|
* Created on: Jun 12, 2013
|
||
|
* Author: delmadord
|
||
|
*/
|
||
|
#include <stdio.h>
|
||
|
//#include <>
|
||
|
|
||
|
#define NUM_WORDS 30
|
||
|
#define WORD_LEN 20
|
||
|
|
||
|
|
||
|
// Reverse words in sentence
|
||
|
int main(void) {
|
||
|
int i = 0, j = 0;
|
||
|
char ch, sentence[NUM_WORDS][WORD_LEN + 1];
|
||
|
printf("Enter a sentence without pucntation: ");
|
||
|
while ((ch = getchar()) != '\n') {
|
||
|
if (ch == ' ') {
|
||
|
sentence[i++][j] = '\0';
|
||
|
j = 0;
|
||
|
}
|
||
|
else
|
||
|
sentence[i][j++] = ch;
|
||
|
}
|
||
|
// Add null character in case of just one word.
|
||
|
sentence[i][j] = '\0';
|
||
|
|
||
|
printf("Reversal of sentence: ");
|
||
|
while (i >= 0)
|
||
|
printf("%s ", sentence[i--]);
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
}
|
||
|
|
||
|
|