Advertisement
ASP_Volume2 Debugging and Error Handling #40201

Beginner's Code: Input string and reverse it

Program inputs a string & prints it out backwards to a file. Found at http://users.neca.com/jboxall/ja05002.htm

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
/* 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]);
   }
}

Upload
Original Comments (3)
Recovered from Wayback Machine