将字符串(单词)拆分为C中的字母

我需要一个字符串来分割成它的字母并将它保存在一个数组中。我不知道如何做到这一点。它可能在C ++中,但在C语言中似乎没有办法做到。

或者,如果有一种方法来获取输入字符串(一个单词)并将其保存为数组中的单独字母将是理想的。我已使用下面提到的代码来获取输入

#include  #include  #include  #include int(){ char inputnumber; printf( "Enter the number" ); // the word is like --> hellooo scanf("%s", &inputnumber); int i=0; printf(inputnumber[i]); } 

更新:这个问题已经解决了,我没有在这里声明一个指向char的指针,那是缺少的部分,然后我们可以逐个读取这个单词,谢谢所有

看看这段代码,看看你的错误

  #include  // #include  // you dont really need this // #include  // or this // #include // or this //int(){ int main (){ // <-- int main here printf( "Enter the number" ); // declare a character array to Store input String char inputnumber[126]; scanf("%s", &inputnumber); /** take a pointer to point to first character **/ char *p = inputnumber; /** iterate through it untill you get '\0' - a speial character indicating the end of string */ while ( *p != '\0' ) { // <- print characters not strings hence c //based on your requirement you can store this in another array printf ("%c ", *p ); p++ ; // move p to point to next position } return 0; // return happyily }