Too many initializers for char b[]

c++

Solution

You have said that `b` is an array of `char`. But you are supplying string literals rather than individual characters. It's impossible to know what you really mean to do. Perhaps you actually want `b` to be an array of strings:

const char* b[] = {".-", ".-", "-...", "-...", ...};

Problem

It is morse code program. I am getting error of `too many initializers for char b[]`. How can I get rid of this error? ``` #include<iostream> using namespace std; int main(){ char a[72]={'A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','Q','q','R','r','S','s','T','t','U','u','V','v','W','w','X','x','Y','y','z','Z','0','1','2','3','4','5','6','7','8','9','.',',','?','\'','!','/','(',')','&','@'}; char b[]={".-",".-","-...","-...","-.-.","-.-.","-..","-..",".",".","..-.","..-.","--.","--.","....","....","..","..",".---",".---","-.-","-.-",".-..",".-..","--","--","-.","-.","---","---",".--.",".--.","--.-","--.-",".-.",".-.","...","...","-","-","..-","..-","...-","...-",".--",".--","-..-","-..-","-.--","-.--","--..","--..","-----","-----",".----",".----","..---","..---","...--","...--","....-","....-",".....",".....","-....","-....","--...","--...","---..","---..","----.","----.",".-.-.-",".-.-.-","--..--","--..--","..--..","..--..",".----.",".----.","-.-.-","-.-.--","-..-.","-..-.","-.--.","-.--.","-.--.-","-.--.-",".-...",".-..."}; char c[40]; cout<<"Enter code "; cin.getline(c,40); for(int i=0;i<1;i++){ for(int j=0;j<72;j++){ if(b[j]==c[i]){ cout<<a[j]; } } } return 0; } ```

Original source