1

I have this:

typedef struct nodebase{
  char name[254];
  char sex;
  int  clientnum;
  int  cellphone;
  struct nodebase *next;
  struct nodebase *encoding;
} clientdata;

I have added clientdata *curr[]; in seperate function. The reason why I made *curr into *curr[] instead is that this client data will be stored in a .txt file. So I came up with singly linked-list to read all the data and when the program fscanf every 5th variable, I will add 1 to clientcounter.

So, the *curr[] will be *curr[clientcounter].

Now, I need to convert this pointer array into char array named temp[clientcounter] because char array is needed to evaluate something else later in the code.

I came up with this code below:(Using Tiny C on Windows)

void loaded_data_transfer(clientdata *curr,clientdata temp[],int clientcounter)
{
clientdata temp[] = {0};

temp[clientcounter].name = curr[clientcounter]->name;
temp[clientcounter].sex = curr[clientcounter]->sex;
temp[clientcounter].clientnum = curr[clientcounter]->clientnum;
temp[clientcounter].cellphone = curr[clientcounter]->cellphone;

}

The problem is, Tiny C is giving me an error: lvalue expected at temp[clientcounter.name = ... part. Can anyone tell me what did I do wrong?

And if anyone knows a better way to keep track of the curr of clientdata by using counter and by using singly linked-list, please let me know.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Beginner C
  • 79
  • 3
  • 12

3 Answers3

2

You cannot assign an array to another. You should use strcpy or strncpy

strcpy(temp[clientcounter].name, curr[clientcounter]->name);
fkl
  • 5,412
  • 4
  • 28
  • 68
  • How about assigning `int`, instead of `char` ? – Beginner C Oct 02 '13 at 11:02
  • @BeginnerC Problem here is not `int` or `char`. It is that `name` is an **array**. – user694733 Oct 02 '13 at 11:10
  • Oh i thought he meant using a single int instead of a char array. I guess i wrote clearly that you cannot copy arrays this way, irrespective of their types. – fkl Oct 02 '13 at 11:11
  • @user694733 I was just asking if there is a way to assign `int` – Beginner C Oct 02 '13 at 11:14
  • @BeginnerC What book or tutorial are you using to learn about C? It sounds like you should review the chapter about value assignments and array assignments/copying. – RedX Oct 02 '13 at 11:18
  • @RedX Actually, I am just a beginner, learning C in school. If you could suggest me a good book, I shall review & learn more. – Beginner C Oct 02 '13 at 11:24
  • 1
    @BeginnerC See [this list](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list). – RedX Oct 02 '13 at 11:25
1

Maybe you meant to copy the entire struct:

void loaded_data_transfer(clientdata * curr, clientdata temp[], int clientcounter)
{
    temp[clientcounter] = *curr; // Copy entire struct
}

It should work, because your struct doesn't any pointer members.

I am assuming you use it like this

clientdata * curr[CURR_SIZE];
clientdata temp[TEMP_SIZE];
/* init curr elements here */
loaded_data_transfer(*curr[clientcounter], temp, clientcounter);
user694733
  • 15,208
  • 2
  • 42
  • 68
  • 1
    You better include the function call as well in code. Then i can help with the precise fix – fkl Oct 02 '13 at 11:15
  • @BeginnerC I had i little misunderstaning what function parameters types you meant to use. I updated my answer. – user694733 Oct 02 '13 at 11:16
0

Also, your declaration should be:

void loaded_data_transfer(clientdata *curr[],...
willus
  • 501
  • 3
  • 7