Some may help * names

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
char** names;
int X, Y;
}
We;

void printNames(We people)
{
int i;
for (i = 0; i < people.Y; i++)
printf("%s\n", people.names[i]);
}

#define MAX 32

int main()
{
int iterator;
int count;

printf("number of names:\n");
scanf("%d", &count);
We people = { NULL, MAX, count };
people.names = malloc ( count * sizeof (char* ) );
for (iterator = 0; iterator < count; iterator++){
people.names[iterator] = malloc(MAX);
scanf("%s", people.names[iterator]);
}

printNames(people);

for (iterator = 0; iterator < people.Y; iterator++)
free(people.names[iterator]);

free(people.names);

return 0;
}
yes? I think we had an article on how to properly ask questions somewhere around here.
Topic archived. No new replies allowed.