hi and thanks for advance,
i have a problem to compare between 2 arrays.
i have a file name fruit_file which has a content like this:
apple
orange
mango
banana
papaya
and i have an seed array from arg list which is;
mango
lime
pineapple
peach
i want to copy seeds from seed_array to fruit_file but not for same fruit.so i have to compare array and file so that no duplicate fruit inside the file.
below is my code and i cant have good output.and this is my output (in fruit_file)
apple
orange
mango
banana
papaya
lime
lime
pineapple
lime
pineapple
peach
i dont know why there r duplicate fruit inside the fruit_file.is it because of my seed_array or what?
char seed[100]="";
char seed_array[100][100];
int main(int argc, char* argv[])
{
count=0;//count d number of seeds
for (int i = 1; i < argc; i++)
{
/* Check for a switch (leading "-") */
if (argv[i][0] == '-')
{
/* Use the next character to decide what to do. */
switch (argv[i][1])
{
case 's': strcpy (seed,argv[++i]);
seed_found=true;
strcpy (seed_array[count],seed);
count++;
seeding();
break;
default: printf ("Invalid selection \n");
break;
}
}
}
printf ("Running Completed......\n");
getch();
return 0;
}
void seeding()
{
FILE *fruit_file;
if ((fruit_file= fopen(fruit, "a+"))
== NULL)
{
fprintf(stderr, "Cannot open output file.\n");
exit(0);
}
char fruit_array[100][100];
int row=0;
char *p=NULL;
while (fgets(fruit_array[row],100,fruit_file) !=NULL)
{
if(p=strchr(fruit_array[row],'\n'))
{
*p='\0';
}
row++;
}
for(int i=1;i<=count;i++)
{
printf("seed=%s\n",seed_array[i]);
for(int bil=0;bil<=row;bil++)
{
if(strcmp(fruit_array[bil],seed_array[i]) != 0)
{
fprintf (fruit_file,"%s\n",seed_array[i]);
}
}
}
}
really need help from u guys!!!!