View Single Post
Old 09-23-2005, 10:54 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Here is one in C
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LENGTH 256

int main()
{
  char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 
		     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 
		     'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '\0'};
		     
  char message[LENGTH +1], temp;
  int i;
  printf("Enter a string: ");
  fflush(stdout);
  fgets(message, LENGTH, stdin);
  message[strlen(message) -1] = '\0'; /* remove '\n' from string */
  message[0] = toupper(message[0]);
  printf("After capitalizing the first letter of this string it becomes: %s\n",
	 message);
  message[strlen(message) -1] = toupper(message[strlen(message) -1]);
  printf("After capitalizing the last letter of this string it becomes: %s\n",
	 message);
  for(i=0; i < alphabet[i]; ++i)
    if(message[0] == alphabet[i])
      {
	message[0] = alphabet[(i+3)%strlen(alphabet)];
	break;
      }
  printf("After adding three to the first letter of this string it becomes: %s\n",
	 message);
  temp = message[0];
  message[0] = message[strlen(message) -1];
  message[strlen(message) -1] = temp;
  printf("After swapping the first and last letters of this string it becomes: %s\n",
	 message);
  return 0;
}
But since you're looking at C++, you might want to use some nifty string functions.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote