objective c - Take user input from scanf and add to a array? -


i'm trying create array of questions enter trivia game. i'm having problems scanf , adding whole questions array. enter first word of question

example: want input "how many bases in baseball?" , have entered allquestions[0], asked next questions entered array, "how" scanf. think need transfer scanf input string addobject array. appreciated. i'm new this.

        nsmutablearray *allquestions = [[nsmutablearray alloc]init];          char *questions[200];         int =0;         (i = 0; < 20; i++) {             nslog(@"next question?");             scanf("%s",&questions);              nslog(@"%s", &questions);             [allquestions addobject:questions[i]];     } 

i hope work you:

nsmutablearray *allquestions = [[nsmutablearray alloc]init]; char questions[20][200]; // can store 20 questions each of length 200  //input each question for(int i=0;i<20;i++) {    nslog(@"next question?");    scanf("%[^\n]%*c",questions[i]);    nsstring *questionstring = [nsstring stringwithcstring:questions[i] encoding:nsasciistringencoding];     [allquestions addobject:questionstring];  }  //print each string for(int i=0;i<20;i++) {    printf("%s",questions[i]);    printf("\n"); } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -