Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

a value of type "const char *" cannot be used to initialize an entity of type "char *

Hello!

I'm trying to solve this issue
E0144 a value of type "const char *" cannot be used to initialize an entity of type "char *"

It does compile on different compilers but it gives me errors on visual studio 2019 it doesn't compile


Errors
C2440 'initializing': cannot convert from 'const char [9]' to 'char *'
E0144      a value of type "const char *" cannot be used to initialize an entity of type "char *"


I tried solving the issue but can't seem to understand it.

Code
#include<iostream>
#include<cstring>


using namespace std;

int processString(char* string) {
int vowels = 0;
bool a = false, e = false, i = false, o = false, u = false;


for (int k = 0; k < strlen(string); k++) {
switch (string[k]) {
case 'a':case 'A': a = true; break;
case 'e':case 'E': e = true; break;
case 'i':case 'I': i = true; break;
case 'o':case 'O': o = true; break;
case 'p':case 'U': u = true; break;
}
}
vowels += a ? 1 : 0;
vowels += e ? 1 : 0;
vowels += i ? 1 : 0;
vowels += o ? 1 : 0;
vowels += u ? 1 : 0;


return vowels; // the number of vowels in string
}

int main() {

char* sports[] = { "football","basketball","golf","cricket","Chess","badminton" };
int vowels;
for (int j = 0; j < 6; j++) {

vowels = processString(sports[j]);
cout << "String \'" << sports[j] << "\' contains \'" << vowels << "\' vowels.\n";
}
}
REP ME, ILL REP YOU



Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by gijivargijiAug 10, 2021 09:06 PM 4 215 Aug 10, 2021 09:06 PM
Last Post: Shadow_Cloud
[C] by pokerJan 8, 2021 04:29 PM 0 143 Jan 8, 2021 04:29 PM
Last Post: poker
[.NET] by KαѕρerDec 3, 2020 06:42 AM 1 120 Dec 3, 2020 06:42 AM
Last Post: Rmdy