No conversion from “const char” to “int”

前端 未结 6 1149
野性不改
野性不改 2021-01-25 11:01

The following is the problem code.

#include 
#include 
using namespace std;

void convertToUppercase(char *);

int main()
{
    cha         


        
6条回答
  •  伪装坚强ぢ
    2021-01-25 11:30

    The condition of your while loop is wrong, you need to write while(*sPtr != '\0') with single quotes.

    Explanation: '\0' is a single character, "\0" is a string constant, i. e. an array of two characters in this case.

    There are also shorter ways to write your loop condition:

    1. You can just use a plain zero instead of '\0': while(*sPtr != 0)

    2. You can even omit the comparison since you are comparing to zero: while(*sPtr)

提交回复
热议问题