Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "make_msg.c"
  5.  
  6. char* concat(const char *s1, const char *s2)
  7. {
  8.     char *result = malloc(strlen(s1) + strlen(s2) + 1);
  9.     strcpy(result, s1);
  10.     strcat(result, s2);
  11.     return result;
  12. }
  13.  
  14. void create_msg_file(char *fname, int n, int taille_info)
  15. {
  16.     int size_msg = 0;
  17.     char *msg_res = malloc(n * (taille_info + 10));
  18.  
  19.     FILE *file = NULL;
  20.     fname = concat(fname, ".msg");
  21.     file = fopen(fname, "wb");
  22.  
  23.     int i;
  24.     for(i = 0; i < n; i++)
  25.     {
  26.         char *msg = make_msg(i, taille_info, &size_msg);
  27.         printf("buff:%s", msg);
  28.         if(i > 0)
  29.             msg_res = concat(msg_res, msg);
  30.         else
  31.             msg_res = msg;
  32.     }
  33.  
  34.     fwrite(msg_res, 1, strlen(msg_res), file);
  35.     fclose(file);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement