I need to edit every character of a string for an assignment; apply a simple Caesar cipher on it. What is the C equivalent of "charAt()"? I remember my prof saying that all strings are terminated with a certain character in C and that you could run a while loop till that character, but I'm not sure how to do it.

C string is an array of characters. You may set or get a character at specific index.

char str[20]="ABC";
str[0]='a'; // replace 'A' with 'a'

C String (char array) is terminated with a '\0' (null) character.

char str[20]="Sample Text";
 int i=0;
 while(str[i]!='\0') {
     /* put your code */
    i++;
 }

Edited 7 Years Ago by __avd: n/a

C string is an array of characters. You may set or get a character at specific index.

char str[20]="ABC";
str[0]='a'; // replace 'A' with 'a'

C String (char array) is terminated with a '\0' (null) character.

char str[20]="Sample Text";
 int i=0;
 while(str[i]!='\0') {
     /* put your code */
    i++;
 }

Thanks. I ended up doing something similar.

This question has already been answered. Start a new discussion instead.