Split a string(a word) to letters in C -


i need string split letters , save in array .i have no clue how .its possible in c++ in c seems there no way do.

or if there way take input string(a word )and save separate letters in array ideal .i have used below mentioned code input

    #include <stdio.h>     #include <stdlib.h>     #include <math.h>     #include<string.h>     int(){ char inputnumber;         printf(  "enter number" );  // word --> hellooo          scanf("%s", &inputnumber); int i=0; printf(inputnumber[i]);     } 

update: solved ,i did not declare pointer char here ,that's part missing can read word letter letter ,thanks

look @ code , see mistakes

        #include <stdio.h>     //  #include <stdlib.h> // dont need     //  #include <math.h> // or     //  #include<string.h> // or         //int(){         int main (){ // <-- int main here                 printf(  "enter number" );                 // declare character array store input string                 char inputnumber[126];                 scanf("%s", &inputnumber);                  /** take pointer point first character **/                 char *p = inputnumber;                  /** iterate through untill '\0' - speial character indicating end of string */                 while ( *p != '\0' ) {                        // <- print characters not strings hence c                       //based on requirement can store in array                         printf ("%c ", *p  );                           p++ ; // move p point next position                 }                  return 0; // return happyily         } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -