Menu

Problem with Character Array

2003-03-03
2012-09-26
  • Patrick C. Connor Jr.

    The following code:

    char sample_array[4] = {"a","b","c","d"};

    when compiled, produces the following error message:

    initialization to `char' from `const char *' lacks a cast

    Why?

     
    • Anonymous

      Anonymous - 2003-03-03

      you should use single quotes for 'char' not double quotes which are for "strings"

       
    • Patrick C. Connor Jr.

      I'm an idiot...thanx...I need coffee!

       
    • Anonymous

      Anonymous - 2003-04-05

      You should do like this :
      char sample_array[4] = {'a','b','c','d'};
      'a' is a character ,but "a" is a string!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.