Thread: Case Sensitivity Help!!!

  1. #1
    Registered User
    Join Date
    Jan 2011

    Unhappy Case Sensitivity Help!!!

    I Have Made A Program On C " Guess The Capital Game"!!! But I Have a Problem in Taking Answer From Users.. I Defaultly Store Answer In An Array.. as You Can See In The Code Below!! The Program Is Working Like This That ... when It Start A Question Came " What Is The Capital Of Pakistan?" And Answer Is "islamabad" Likewise 25 Question Came Step By Step.... But I Defaultly Store Answers In Lower Case If User Type "IslaMabad" << Like This ... It Consider Answer Wrong ... So Please Help Me That How Can i Remove Case Sensitivity In It So That If User Write In Any Case The answer Should Consider Correct.... Thanks!

    void main()
      char country[25][50]={"Pakistan","Afghanistan","China","Srilanka","United Kingdom","India","Italy","America","Australia","Iran","Turkey","New Zealand","Ireland","Bangladesh","Zimbabwe","South Africa","Kenya","Iraq","Germany","Switzerland","Syria","Israel","Denmark","Japan","Indonesia"};
      char capital[25][50]={"islamabad","kabul","belgium","columbo","london","new dehli","rome","washington","canberra","tehran","istanbul","wellington","dublin","dhaka","harare","pretoria","nairobi","baghdad","berlin","berne","damascus","jerusalem","copenhegen","tokyo","jakarta"};
      char answer[25][50];
      int i=0;
      int score=0;
      printf("************* Welcome To Guess The Capital General Knowledge Game! *************");
      printf("\n===================> Read Below Before Play<===================");
      printf("\n1) You Have To Answer 25 Questions!\n2) All Answers Should Be In Small Letters Otherwise Your Answer Will Be Consider Wrong\n3) Write Spellings Carefully. If Your Spelling is Incorrect Your Answer Will Consider Wrong And Your Score Will Not Counted..! \n/////////////////// Enjoy Playing! \\\\\\\\\\\\\\\\\\\\");
      printf("\n\n///////////////=====>> Game Made By 'Ali Raza' <<=====////////////////");
        printf("\n\n\nQ.%d: What Is The Capital Of %s?",i+1,country[i]);
        printf("\nAnswer: ");
          printf("==>> Answer Is Correct! <<==");
          printf("==>> Answer Is Wrong! <<==\n==>> Correct Answer Is: '%s' <==",capital[i]);
      printf("\n\n*****=====>> Your Score Is %d/25 <<=====*****",score);
      printf("\n\n\n///////////////=====>> Game Made By 'Ali Raza' <<=====////////////////");

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    For someone complaining about case, your capitalisation abuse is a joke.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    If you
    #include <ctype.h>

    then you can use char = tolower(char), to change the answer the user gives, into it's lowercase equivalent, before you test it to see if it's the right answer.

    len = strlen(answerFromUser);
       lowerstring[i]= answerFromUser[i];
    Now test lowerstring with your answer ( using strcmp() ).

  4. #4
    Registered User
    Join Date
    Jan 2011
    Convert the user's answer string into lower case. And have your capital list also in lower case(as you have already had in capital array). Now you easily can compare both strings by strcmp() function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 08-30-2010, 09:26 AM
  2. Replies: 2
    Last Post: 11-01-2009, 09:54 AM
  3. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  4. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM