Code:
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int main(){
int num_players;
char example[10];
char *players_array[3];
char *cerial[2] = {"apple", "Cinammon"};
printf("How many players are playing?");
scanf("%d", &num_players);
getchar();
int x = 0;
int y;
for(x = 0; x<3; x++){
fgets(example, 10, stdin);
example[strlen(example)-1] = '\0';
players_array[x] = example;
}
for(x = 0; x <3; x++){
printf("\n%s\n", players_array[x]);
}
return 0;
}
1. When I enter 3, john, blake, david, it prints out david 3 times.
2. I'm trying to use fgets to get the strings for the pointer array
What am I doing wrong?