which method c do this? thanks
for example, a string [] = "abc";
a array[4];
array[0] = 'a';
array[1] = 'b';
array[2] = 'c';
thanks
Why don't you just subscript it...
int main() {
char *str = "hello";
printf("%c", str[0]); // h
return 0;
}
You can also use array syntax to define the string char str[] = "hello".
#include <string.h>
#include <stdio.h>
int main() {
char str[] = "hello";
int i;
int strLength = strlen(str);
for (i = 0; i < strLength; i++) {
printf("[%c]", str[i]);
}
return 0;
}
[h][e][l][l][o]
A string in C is actually an array of characters so you don't have to do anything.
retrieve it like so
char *string = "abcdef";
for (int i = 0; i < 7; ++i) {
printf("%c\n", string[i]);
}