I've posted this code before. Now I'm trying to take the names that I get out of this file I'm reading, and put them into a structure so I can have an array of my names retrieved.
This part is the part giving me the same error for each line.
Code:
all[i].name = name;
all[i].item = item;
This is my code so far.
Code:
#include <stdio.h>
#include <stdlib.h>
struct names
{
char name[15];
char item[99];
int amount;
};
int main(void)
{
char buffer[50];
char name[15];
char item[99];
int amount;
FILE *fp;
FILE *fp2;
int i=0;
if ( (fp = fopen("names.csv", "r" )) == NULL )
{
printf("Couldn't open file\n");
exit(1);
}
while(fgets(buffer, sizeof(buffer), fp))
{
sscanf(buffer,"%[^,] ,%[^,], %d", &name, &item, &amount);
strcat (name, ".txt");
struct names all[100];
all[i].name = name;
all[i].item = item;
all[i].amount = amount;
i++;
//create file for names
if( (fp2 = fopen(name, "a")) == NULL )
{
printf("unable to open %s\n", name);
exit( 1 );
}
fprintf(fp2, "%s,%d\n", &item, amount);
fclose(fp2);
}
fclose(fp);
}