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.

Recommended Answers

All 2 Replies

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++;
 }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.