I am trying to create a gift exchange list generator, but for whatever reason this won't compile. My uncle who programs for a living was unable to find a problem with it. Here is what I got at the moment..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, const char * argv[]) {
int NumPeople;
int i;
int RandNum;
typedef struct _Names
{
char fromname[20];
char toname[20];
} Names[100];
printf("How many people you would like on your list.\n");
scanf("%d", &NumPeople);
if ( NumPeople > sizeof(Names))
{
printf("cannot have more than %d entries\n", sizeof(Names) );
return 20;
}
for (i = 1; i <= NumPeople; i++)
{
printf("Enter name number %d.\n", i);
scanf("%s", Names[i].fromname );
}
for (i = 0; i <= NumPeople; i++)
{
RandNum = rand() % NumPeople + 1;
if ( 0 != strcmp(Names[i].fromname, Names[RandNum].fromname ))
{
strcpy( Names[i].toname, Names[RandNum].fromname);
}
}
for (i = 0; i <= NumPeople; i++)
{
printf("%s -> %s\n", Names[i].fromname, Names[i].toname);
}
return 0;
}