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.

6
  • You say that curr is clientdata *curr[] in main, but the curr in your function is clientdata *curr, what's up with that? Commented Oct 2, 2013 at 10:57
  • @us2012 Sorry, I fixed it. Commented Oct 2, 2013 at 11:03
  • 1
    Why do you create second variable clientdata temp[] = {0}; when you already have one temp on function parameter list? Commented Oct 2, 2013 at 11:03
  • @user694733 I thought clientdata temp[] = {0}; would initialize the temp in function parameter list? Commented Oct 2, 2013 at 11:05
  • @BeginnerC: No. You're declaring and initialising a new variable. You cannot initialise something that already exists. The parameter is initialised at the call site (ideally). Commented Oct 2, 2013 at 11:40

3 Answers 3

2

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

strcpy(temp[clientcounter].name, curr[clientcounter]->name);
Sign up to request clarification or add additional context in comments.

7 Comments

How about assigning int, instead of char ?
@BeginnerC Problem here is not int or char. It is that name is an array.
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.
@user694733 I was just asking if there is a way to assign int
@BeginnerC See this list.
|
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);

2 Comments

You better include the function call as well in code. Then i can help with the precise fix
@BeginnerC I had i little misunderstaning what function parameters types you meant to use. I updated my answer.
0

Also, your declaration should be:

void loaded_data_transfer(clientdata *curr[],...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.