Thread: case sensitive

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    case sensitive

    hey
    im currently making a quiz and....:
    *i want to make sure capitals dont matter i use fgets to get the correct answer out of a txt file
    is there anyway how to make it non-case sensitive.
    *theres a char questions[100]; and i say somewhere in my code
    while(questions!=EOF); and at this thing the compiler says its a comparisonbetween a ptr and an integer
    just wanna know how to solve that coz somehwere in a bok i read something similar like c!=EOF where c=fscanf(fp,"%s",oneword); and apperently it worked there....

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    First, make sure all answers are written in uppercase letters. Then, before you check for a match, use the toupper() function on all characters in the string the user inputs. This will make all characters upper case, thus no problems when comparing.

    (Can of course be done the other way with lower case letters and tolower() too )
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    while(questions != EOF)

    Well, questions is in this case a pointer to the first element of a char array. But you want to check the value (not the adress) that the pointer is pointing to, so you would need at least something like this:

    while(*questions != EOF)

    But that's not what you want, I guess.


    c!=EOF where c=fscanf(fp,"%s",oneword);

    Here, the variable c is assigned the return value of the fscanf() function to test for EOF.

    So, what you want may be to check the return value of the function you are using for reading from the text file.
    Perhaps something like this:
    Code:
    #define SIZE 100
    ...
    FILE *fd;
    ...
    char questions[SIZE];
    ...
    while(fgets(questions, SIZE, fd) != NULL)
    {
        do_something;
    }
    Last edited by Sargnagel; 11-08-2002 at 05:55 PM.

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    Talking thanx

    yup i used tolower(); and it worked thank u magos and sargnagel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Intel syntax on MinGW ?
    By TmX in forum Tech Board
    Replies: 2
    Last Post: 01-06-2007, 09:44 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. returning to a spot in the code
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 09-22-2001, 05:24 AM