Thread: this error is extremely confusing....

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001

    Question this error is extremely confusing....

    Can somebody explain this error to me?:
    error C2440: '=' : cannot convert from 'char [2]' to 'char'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    I get this error whenever I try to do something like the following:
    char en[256];
    int i = 0;
    while(i < 256)
          if(en[i] == 'A' || 'a')
             en[i] = "P";
    // ...continues...I didn't wanna post it all
    What's wrong here?

  2. #2


    Well to start off its an infinte loop, I will never be greater than 256, try setting up a for loop

    char en[256];

    //initialize the array some where between here and the start of
    // the for loop.
    char filler = "p";
    like for(i=0; i<256; i++){
    //and im guessing you want to replace all instances of
    //A and with the letter P. so...
    if(en[i] == "a" || "A")
    en[i] = filler;
    }//for loop

  3. #3
    Registered User
    Join Date
    Dec 2001
    the problem is the " instead of a single '
    when using single char's use ' around the char
    en[i] = 'P'; is what you want
    oh and that if statment has a logic error
    i think you want
    if( (en[i] == 'A') || (en[i] == 'a') )
    if( toupper(en[i]) == 'A')
    "char toupper(char)" is a function in ctype.h that will return the uppercase version a the paramater if it is lower case.
    either line of code will work instead of "if(en[i] == 'A' || 'a')"

  4. #4
    I'm Back
    Join Date
    Dec 2001
    i agree with rpimatty on the upper-lower case thing

    and also in the while loop you haven't incremented the val of i by 1
    Last edited by ihsir; 12-23-2001 at 01:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf is confusing me.
    By babelosopher in forum C Programming
    Replies: 10
    Last Post: 07-12-2007, 04:22 PM
  2. confusing error messages?
    By ssjnamek in forum C Programming
    Replies: 6
    Last Post: 01-26-2006, 08:56 PM
  3. Extremely odd Serialization error
    By VirtualAce in forum Windows Programming
    Replies: 12
    Last Post: 01-02-2006, 01:55 PM
  4. Arrays are confusing...
    By GavinHawk in forum C Programming
    Replies: 10
    Last Post: 11-29-2005, 01:09 AM
  5. Confusing Pointer
    By loko in forum C Programming
    Replies: 4
    Last Post: 08-29-2005, 08:52 PM