LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   memcpy problems (https://www.linuxquestions.org/questions/programming-9/memcpy-problems-364017/)

alaios 09-16-2005 03:48 PM

memcpy problems
 
HELP
Code:

memcpy(&send_qdisc_stats,&log_qdisc_stats,sizeof(log_qdisc_stats));
                printf("Prin tin allagi sto reconfigure prin to set %s \n",log_qdisc_stats[0].htbstats.rate);
                printf("Prin tin allagi sto reconfigure prin to set %s \n",log_qdisc_stats[0].htbstats.ceil);



                printf("Prin tin allagi sto reconfigure prin to set %s \n",send_qdisc_stats[0].htbstats.rate);
                printf("Prin tin allagi sto reconfigure prin to set %s \n",send_qdisc_stats[0].htbstats.ceil);

This programme at execution prints the following...HELP memcpy dont work.... and dont know how to use it

Prin tin allagi sto reconfigure prin to set 100Kbit
Prin tin allagi sto reconfigure prin to set 100Kbit
Prin tin allagi sto reconfigure prin to set
Prin tin allagi sto reconfigure prin to set

itsme86 09-16-2005 03:53 PM

Thanks for supplying so much relevant information such as the definitions for send_qdisc_stats and log_qdisc_stats. It makes helping you so much easier. After 1264 posts one would think you'd know that.

itsme86 09-16-2005 03:57 PM

Anyway, here's an example of how to properly use memcpy():
Code:

#include <stdio.h>
#include <string.h>

int main(void)
{
  struct foo { int a; int b; };
  struct foo one = { 10, 20 };
  struct foo two;

  memcpy(&two, &one, sizeof(one));

  printf("two.a = %d, two.b = %d\n", two.a, two.b);

  return 0;
}

The output is:
two.a = 10, two.b = 20

alaios 09-17-2005 02:31 AM

extern union qdisc log_qdisc_stats[10];
union qdisc send_qdisc_stats[10];



struct htb{
char prio[maxlength];
char rate[maxlength];
char ceil[maxlength];
char burst[maxlength];
char cbusrt[maxlength];
};

struct cbq{
char allot[maxlength];
char avpkt[maxlength];
char bandwidth[maxlength];
char rate[maxlength];
char mpu[maxlength];
char bytes[maxlength];
};

struct tbf{
char burst[maxlength];
char mpu[maxlength];
char rate[maxlength];
char peakrate[maxlength];
};



union qdisc{
struct htb htbstats;
struct cbq cbqstats;
struct tbf tbfstats;
};

addy86 09-17-2005 07:26 AM

Is the code in your original post the exact code or is there something in between?
Have you tried debugging with gdb?


All times are GMT -5. The time now is 10:23 AM.