Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5.  
  6. typedef struct TestStruct {
  7.     char * data;
  8.     unsigned long long size;
  9. }TestStruct;
  10.  
  11. void func2 (TestStruct * tmp) {
  12. tmp->size = 1;
  13. printf("%i\r\n",tmp->size);
  14. tmp->data = NULL;
  15. tmp->data = realloc(tmp->data, 20);
  16. if (tmp->data != NULL) {
  17. memcpy(tmp->data,"12334",6);
  18. strcat(tmp->data,"asadsd");
  19. printf("%i %s\r\n",tmp->size,tmp->data);
  20. }
  21. }
  22.  
  23. void func1(TestStruct ** tmp) {
  24. *tmp = malloc(sizeof(TestStruct) * 2);
  25. func2(&(*tmp)[0]);
  26. }
  27. int main () {
  28. TestStruct * tmp;
  29. func1(&tmp);
  30. printf("%i %s\r\n",tmp[0].size,tmp[0].data);
  31. getchar();
  32. return 0;
  33. }