/************************************************** * CP-I Warmup 1999-2000 * Problem #7 *************************************************/ /* * Question: * * Write a function reverse(char s[]); that reverses the character * string s. * Use it to write a program that reverses its input a line at a time. */ #include <stdio.h> #define MAX_LENGTH 100 main() { char str[MAX_LENGTH]; printf("Terminate input with \".\" in a newline\n"); printf("Give the Input:\n"); while(1) { scanf("%[^\n]",str); fflush(stdin); getchar(); if(!strcmp(str,".")) break; reverse(str); printf("%s\n",str); } } int reverse(char s[]) { int i,len; char temp; len=strlen(s); for(i=0;i<=len/2;i++) { temp=s[len-1-i]; s[len-1-i]=s[i]; s[i]=temp; } }