Feb 4, 2017 at 10:33pm UTC
how i create a table with alphanumeric data? like a[1]=one?
i type this
void main(){
const char a[]={"one","two","three","four","five","six","seven","eight","nine"};
int n;
cin >> n;
if(n>9)
{cout<<a[n]<<endl;}
else
{cout<<"greater than 9"<<endl;}
}
and shows me those errors
Error 1 error C2078: too many initializers
2 IntelliSense: expected a '}'
Last edited on Feb 4, 2017 at 10:44pm UTC
Feb 4, 2017 at 11:30pm UTC
You created an 1 dimensional array of chars but are
using initializing it like its a 2 dimensional array. Why not use an array of strings instead? It would be much easier than what you are currently attempting.
Reference:
http://www.cplusplus.com/reference/string/
To accomplish what your currently attempting:
1 2 3 4 5
int main() {
const char a[9][5] = { {'o' , 'n' , 'e' },
{'t' , 'w' , 'o' } };
return 0;
}
Last edited on Feb 4, 2017 at 11:37pm UTC
Feb 5, 2017 at 10:02am UTC
thanks guys..you are really helpfull..!!
@whitenite1 you are right, my mistake.. i write the code 2 pm...
Last edited on Feb 5, 2017 at 10:03am UTC