I want to iterate through a word and print each of its characters, together with its ASCII number.
I've tried
#include <iostream>
#include <stdio.h>
using std::cout;
int main()
{
char cWord[30] = {"Larissa"};
int iCounter = 0;
char cLetter = cWord[iCounter];
for (iCounter = 0; iCounter < 5; iCounter++) {
printf("%c == %d \n", cLetter, cLetter);
}
}
but that just prints L == 76 five times. I suppose that means the cLetter variable doesn't update as I run the for loop, but I don't understand why.
You need to update
cLetterin the loop, there's no magic connection to earlier code. Might as well movecLetters scope to inside the loop as well. TryHere,
iCounteris updated each iteration, and thereforecLetteris too.