//************************************** // Name: Beginner's Code: Input string and reverse it // Description:Program inputs a string & prints it out backwards to a file.Found at http://users.neca.com/jboxall/ja05002.htm // By: Found on the World Wide Web (from psc cd) // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** /* Jason Boxall 1/13/97 CSC 131 Lab#5*/ /* This program inputs a name(s) and prints it(them) out backwards */ #include <stdio.h> #include <string.h> FILE *fout; void main() { char name[20]; char *getname();/* Fuction prototype */ void switcheroo(char *);/* Fuction prototype */ fout=fopen("a:lab5out.dat","w"); strcpy(name,getname()); while(strcmp("q",name)) { switcheroo(name); fprintf(fout,"\n"); strcpy(name,getname()); } } char *getname() { char name[20]; printf("\n\nEnter in a name to print backwards or 'q' to quit: "); gets(name); return name; } void switcheroo(char *name) { int x,i; x=strlen(name); for(i=(x-1);i>=0;--i) { putchar(name[i]); fprintf(fout,"%c",name[i]); } }