S
S
Saymon_K2014-11-11 18:33:41
C++ / C#
Saymon_K, 2014-11-11 18:33:41

How to add a new character to a character array?

I would never have thought that I would ask such... "obvious" questions. But be that as it may, I really got stuck when I tried to put an element into the array:
char mass[100];
mass[0] = "e";
To which Visual Studio told me
error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
So what should I do???
PS Sorry for all the stupidity of the question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2014-11-11
@dnovikoff

Change quotes from double to single. "e" is an array of two elements: character "e" and terminating null. Whereas 'e' (in single quotes) is a character.

B
BladgeR, 2014-11-11
@BladgeR

You can do it as dnovikoff wrote, or in this way: "char mass[]= "e";".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question