0
#include<stdio.h>
#include<cs50.h>
#include<string.h>
int main(void)
{
string name = get_string("Enter: ");
printf("%s\n",name);
int n = strlen(name);
printf("%i\n",n);
for(int i = 0, i < n, i++)
while name[i] != ("\0");
printf("%i",name[i]);

}

Getting this error message (with helpcs50 make caesar):

Asking for help...

caesar.c:10:16: error: redefinition of 'i'

Not quite sure how to help, but focus your attention on line 10 of caesar.c! caesar/ $

(https://www.canva.com/design/DAE1OZ8K7lw/hIfd2XEnzAzhrcCha_ptnQ/view?utm_content=DAE1OZ8K7lw&utm_campaign=designshare&utm_medium=link&utm_source=sharebutton)

Unable to figure out redefinition of i, i is not defined earlier in this code. %i on the previous line is something different.

2

2 Answers 2

0

I think the question from DinoCoderSaurus answers the question. Have you tried compiling again, since making that correction?

0

After getting replies (also on CS50 eDX forum) and reworking, here is the code that seems to achieve the intermittent goal of finding ASCII code of entered characters. There was no need of while loop and it was an error as the same leads to infinite loop. Even if there was a need, I should perhaps have opted for if command.

#include<stdio.h>
#include<cs50.h>
#include<string.h>
int main(void)
{
    string name = get_string("Enter: ");
    printf("Entered text by user: %s\n", name);
    int n = strlen(name);
    printf("lenght of entered text: %i\n", n);
    for (int i = 0; i < n; i++)
    {
        printf("ASCII code %i\n", name[i]);
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .