c - Confused with making an input into an empty array. -


say make input : "hello world" // hit new line "goodbye world" // second input

how scan through 2 lines , input them separately in 2 different arrays. believe need use getchar until hits '\n'. how scan second input.

thanks in advance. beginner in c please it'd helpful without pointers haven't covered topic.

try code out :

#include<stdio.h> int main(void)   {    int flx=0,fly=0;    char a,b[10][100];    while(1)      {       a=getchar();       if(a==eof) exit(0);       else if(a=='\n')         {          flx++;          fly=0;          }        else         {          b[flx][fly++]=a;           }     }   } 

here use 2 dimensional array store strings.i read input character character.first create infinite loop continues reading characters.if user enters end of file character input stops. if there newline character flx variable incremented , next characters stored in next array position.you can refer strings stored b[n] n index.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -