About Assignment

N

nick048

Hi to all,

I have this declaration:

struct node
{
char info[BUFLEN] ;
struct node *next ;
} ;


and in the main

char msg[BUFLEN];

After the initialition of string with (for example)

i=0;
char_recv = recv(newsocketfd, &c, 1, 0);
while (c !='\n')
{
msg[i++]=c;
char_recv = recv(newsocketfd, &c, 1, 0);
} /* End while (c !='\n') */


I need to insert msg into my list; if I write
p = malloc(sizeof(struct node));
p->info = msg;
p->next = first;
first = p;


the compiler return to me the message:
error: incompatible type in assignement

How can to correct the error ? I hope in Your help.

Best Regards
Gaetano
 
C

Cong Wang

Hi to all,

I have this declaration:

struct node
{
char info[BUFLEN] ;
struct node *next ;

} ;


and in the main

char msg[BUFLEN];

After the initialition of string with (for example)

i=0;
char_recv = recv(newsocketfd, &c, 1, 0);
while (c !='\n')
{
msg[i++]=c;
char_recv = recv(newsocketfd, &c, 1, 0);

} /* End while (c !='\n') */


I need to insert msg into my list; if I write
p = malloc(sizeof(struct node));


Check whether 'p' is NULL, please.
p->info = msg;

You really want "strcpy(p->info, msg);", right?
 
N

nick048

Hi to all,
I have this declaration:
struct node
{
    char info[BUFLEN] ;
    struct node *next ;

and in the main
char msg[BUFLEN];
After the initialition of string with (for example)
i=0;
char_recv = recv(newsocketfd, &c, 1, 0);
while (c !='\n')
{
  msg[i++]=c;
  char_recv = recv(newsocketfd, &c, 1, 0);

} /* End while (c !='\n') */
I need to insert msg into my list; if I write
p = malloc(sizeof(struct node));


Check whether 'p' is NULL, please.
   p->info = msg;

You really want "strcpy(p->info, msg);", right?- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

Yes,
I have tried the assignment with strcpy() and all work fine.
Thank You
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top