For example, if I’m doing a for loop such as follows:
assume the string has been made into a char array already
for(i=0;i<somestring.length;i++)
somestring[i] = somestring[i] + i;
why doesn’t the previous work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The result of
char + intis anint– so you’d need to cast tochar:Or use the implicit conversion available when using
+=:However, generally performing arithmetic on characters is a bad idea. Bear in mind that you can easily end up with unprintable characters this way. What are you trying to achieve?