#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define ANSWER "GRANT"
#define MAX 40
void tup(char *, int );
int main(int argc, char * argv[])
{
  char try[MAX];
  puts("Who is buried in Grant's tomb?");
  gets(try);
  tup(try, strlen(try));
  while (strcmp(ANSWER, try)) { 
    puts("No, thats wrong, Try again."); 
    gets(try);
    tup(try, strlen(try));
  } 
  puts("Thats right."); 
  return 0;
}
//将字符串中的小写字母转换成大写字母
void tup(char *s, int n)
{

  int i;
  for (i = 0; i < n; i++)
    {
      if (*(s + i) >= 'a' && *(s + i) <= 'z')
	*(s + i) -= 32;
    }
}


Published

21 February 2012