Hi all,
Can someone please tell me what is wrong with the code below.i get a " "curr->name" is not an lvalue,but occurs in a context that requires one.curr->name=list1;" message when i compile it.
Why is that?
Thank you.
#include<string.h>
#include <stdio.h>
#define CHARS 30
#define NAMES 20
main()
{
struct NODE {
char name[CHARS];
struct NODE *next;
};
typedef struct NODE Node;
int count= -1;
int i,j,x;
char list1[NAMES][CHARS],list2[NAMES][CHARS];
FILE *fp;
Node* head;
Node* curr;
head=(Node*)malloc(sizeof(Node));
curr=head;
fp=fopen("merge.dat","r"
;
while (!feof(fp)) {
count++;
fscanf(fp,"%s %s ",list1[count],list2[count]);
}
fclose(fp);
while(i<count && j<count)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
if(strcmp(list1,list2[j])<0)
{
curr->name=list1;
j++;
}
else
{
curr->name=list2[j];
i++;
}
}
if (i=count-1)
for(x=j;x<count;x++)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
curr->name=list2[x];
}
else
for(x=i;x<count;x++)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
curr->name=list1[x];
}
}
Can someone please tell me what is wrong with the code below.i get a " "curr->name" is not an lvalue,but occurs in a context that requires one.curr->name=list1;" message when i compile it.
Why is that?
Thank you.
#include<string.h>
#include <stdio.h>
#define CHARS 30
#define NAMES 20
main()
{
struct NODE {
char name[CHARS];
struct NODE *next;
};
typedef struct NODE Node;
int count= -1;
int i,j,x;
char list1[NAMES][CHARS],list2[NAMES][CHARS];
FILE *fp;
Node* head;
Node* curr;
head=(Node*)malloc(sizeof(Node));
curr=head;
fp=fopen("merge.dat","r"
while (!feof(fp)) {
count++;
fscanf(fp,"%s %s ",list1[count],list2[count]);
}
fclose(fp);
while(i<count && j<count)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
if(strcmp(list1,list2[j])<0)
{
curr->name=list1;
j++;
}
else
{
curr->name=list2[j];
i++;
}
}
if (i=count-1)
for(x=j;x<count;x++)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
curr->name=list2[x];
}
else
for(x=i;x<count;x++)
{
curr->next=(Node*)malloc(sizeof(Node));
curr=curr->next;
curr->name=list1[x];
}
}