hey, i have only been working with c for a very short time and i have a queston that seems to be poorly covered in all areas i have looked.
i am attempting to create an array of strings so that 9 strings start out as "----------" then are replaced by user input with a for loop. Knowing that strings are just character arrays, i initially tried just creating a 2d character array but it became quickly apparent that this was not the best way to go about it. after some research, i have been trying to use pointers, but the code is still not working properly. relevant code is as follows:
unfortunetly, this every time the user enters a string, it changes all strings to that value instead of only the intended one. a steer in the correct direction would be greatly appreaciated.
Thanks.
i am attempting to create an array of strings so that 9 strings start out as "----------" then are replaced by user input with a for loop. Knowing that strings are just character arrays, i initially tried just creating a 2d character array but it became quickly apparent that this was not the best way to go about it. after some research, i have been trying to use pointers, but the code is still not working properly. relevant code is as follows:
Code:
char *batter[9] = {
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------"
};
int main(int argc,char *argv[])
{
for(l = 0; l < 9; l++) {
printf("\n\nWhat is the name of batter %d?",l+1);
gets(batter[l]);
clr();
for(k = 0; k < 9; k++) {
printf("%s \n",batter[k]);
}
}
return 0;
}
Thanks.
Comment