Guest User

Untitled

a guest
Feb 21st, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define MAX 128
  4.  
  5. typedef struct hoge{
  6. char name[MAX];
  7. char mail[MAX];
  8. }Hoge;
  9.  
  10. int main(){
  11. Hoge * hoge, *init;
  12. int i;
  13.  
  14. hoge = (Hoge *)malloc(sizeof(Hoge) * 3);
  15. init = hoge;
  16.  
  17. strcpy(hoge->name, "aaa");
  18. strcpy(hoge->mail, "aaa@a.com");
  19. hoge++;
  20. strcpy(hoge->name, "bbb");
  21. strcpy(hoge->mail, "bbb@a.com");
  22. hoge++;
  23. strcpy(hoge->name, "ccc");
  24. strcpy(hoge->mail, "ccc@a.com");
  25.  
  26. hoge = init;
  27.  
  28. for(i = 0; i<3; i++, hoge++)
  29. printf("name: %s\n", hoge->name);
  30.  
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment