Retrieve Characters from String in C
In C language, you can use a loop structure to read each character in a string.
For example, you can use a for loop to iterate through the string and read each character one by one.
#include <stdio.h>
int main() {
char str[] = "Hello, World!";
for (int i = 0; str[i] != '\0'; i++) {
printf("%c ", str[i]);
}
return 0;
}
In the example above, a for loop is used to iterate through the string str until the end symbol ‘\0’ is encountered. During each iteration, the printf function is used to print out each character in the string.