basic strcmpi question

This is a discussion on basic strcmpi question within the C++ Programming forums, part of the General Programming Boards category; Apparently, if (!strcmpi("e", command[4])) is bad, what should I be using instead? Code: #include <iomanip> #include <iostream> #include <fstream> #include ...

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    basic strcmpi question

    Apparently, if (!strcmpi("e", command[4])) is bad, what should I be using instead?

    Code:
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    #include <stdlib>
    #include <conio>
    #include <time>
    #include <ctype>
    
    int main()
    {
    char command[256];
    cin.getline(command, 256, '\n');
    cout<<command;
    if (!strcmpi("a", command[0]))
    {
    cout<<"1";
    }
    if (!strcmpi("b", command[1]))
    {
    cout<<"2";
    }
    if (!strcmpi("c", command[2]))
    {
    cout<<"3";
    }
    if (!strcmpi("d", command[3]))
    {
    cout<<"4";
    }
    if (!strcmpi("e", command[4]))
    {
    cout<<"5";
    }
    
    return 0;
    }
    AIM: MarderIII

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    It's not bad, it's wrong. strcmpi takes two char*, you pass it 1 char* and 1 char.
    If you want to compare two single characters, use ==

    if('a' == command[0])
    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
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    what is meant by char* ?
    AIM: MarderIII

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Pointer to a char. Basically an array (string).
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic math programming question
    By hebali in forum C Programming
    Replies: 38
    Last Post: 02-25-2008, 03:18 PM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 02:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 02:24 AM
  4. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 03:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21