0

I'm writing a program that is supposed to take in a list of names from the user, store them in an array, and then search through the list to check and see if the next name the user enters is part of the original list of names. The issue I'm having is that when I go to enter a list of names, it only saves the last name entered into the list. I've searched the web and this site for similar issues, but I can't seem to find anything that answers this issue specifically. Here is the part of code dealing with my problem

void initialize(char names[][],const int MAX_NAMES,const int MAX_NAMELENGTH)
{
     int i,Number_entrys;


     printf("How many names would you like to enter to the list?");
     scanf("%d",&Number_entrys);

     if(Number_entrys>MAX_NAMES){
                   printf("Please choose a smaller entry");
                   }else{
      for (i=0; i<Number_entrys;i++){
     scanf("%s",names);

     }
   }

  printf("%s",names); 

}

I'm new to C, and trying very hard to teach myself, so be gentle lol.

2
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by jcmoney1010
0
for (i=0; i<Number_entrys;i++)
{
    scanf("%s",names);
}

You are looping here to obtain "number_entrys" entries, but you do not use your counter. Change it to this:

for (i = 0; i < Number_entrys; i++)
{
    scanf("%s",names[i]);
}

I'm also not sure what the goal is of this statement:

printf("%s",names);

But be aware this likely won't print anything truly useful. If you want to print all names you should loop over the 2-dimensional array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.