I'm trying to write a program that all yous to enter a name into an array and them print that name when you type in it's index. The print command is in a function separate from the main one. The problem is that whenever I try to print that name, I always get (null).
Here is the code I am working with:
Code:
char *first[50];
char *last[50];
char blank[50];
char blank2[50];
int _tmain(int argc, _TCHAR* argv[])
{
printf("Enter a name (last, first): ");
scanf("%s %s", &blank2, &blank);
first[i] = blank;
last[i] = blank2;
printf("%s %s", &*last[i], &*first[i]);
i = i + 1;
getchar();
//To test the program, I have it print out the name I just entered. This part works works fine.
printf("Enter the index of the name you wish to see (realize that the numbers start a 0): ");
scanf("%s", &number);
print(number);
}
void print(int index){
printf("%s %s", &*last[index], &*first[index]);
getchar();
//this is the problem area.
//I want to print the name associated with the index I inputed, but all I get is two "(null)'s",
//one for the first name and one for the last name.
}
By the way, I'm programming using Visual Studio.