Advertisement
Guest User

code

a guest
Feb 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. /**
  2. * main.c
  3. *
  4. * Ce fichier contient la fonction main() du programme de manipulation
  5. * de fichiers pnm.
  6. *
  7. * @author: Nom Prenom Matricule
  8. * @date:
  9. * @projet: INFO0030 Projet 1
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <assert.h>
  15. #include <unistd.h>
  16. #include <ctype.h>
  17. #include <getopt.h>
  18.  
  19. #include "pnm.h"
  20.  
  21. struct RGB_t
  22. {
  23. unsigned short red;
  24.  
  25. }
  26.  
  27. struct PBM_t
  28. {
  29. unsigned rowsSize;
  30. unsigned columnsSize;
  31. unsigned **matrix;
  32. };
  33.  
  34. PBM *create_pbm(unsigned rowsSize, unsigned columnsSize)
  35. {
  36. unsigned **matrix = malloc(columnsSize * sizeof(unsigned *));
  37. if (matrix == NULL)
  38. return NULL;
  39.  
  40. for (unsigned i = 0; i < columnsSize; i++)
  41. {
  42. matrix[i] = calloc(rowsSize, sizeof(unsigned));
  43. if (matrix[i] == NULL)
  44. {
  45. for (unsigned j = i; j >= 0; j++)
  46. free(matrix[i]);
  47.  
  48. free(matrix);
  49. }
  50. }
  51. ¨
  52. PBM *pbm = malloc(sizeof(PBM));
  53. if (pbm == NULL)
  54. {
  55. for (unsigned i = 0; i < columnsSize; i++)
  56. free(matrix[i]);
  57.  
  58. free(matrix);
  59. }
  60.  
  61. pbm->rowsSize = rowsSize;
  62. pbm->columnsSize = columnsSize;
  63. pbm->matrix = matrix;
  64.  
  65. return pbm;
  66. }
  67.  
  68.  
  69.  
  70. if (buffer[0] != '#')
  71. {
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. int main(int argc, char *argv[]) {
  82.  
  83. char *optstring = "";
  84.  
  85. /* Insérez le code ici */
  86.  
  87. return 0;
  88. }
  89.  
  90. typedef struct PNM_t PNM;
  91.  
  92. struct PNM_t
  93. {
  94. PBM *pbmxd;
  95. Type format;
  96. unsigned colonnes;
  97. unsigned lignes;
  98. char filename[50];
  99. };
  100.  
  101. struct PBM
  102. {
  103. unsigned colonnes;
  104. unsigned lignes;
  105. char filename[50]; /LOIC
  106. };
  107.  
  108. PNM *createPNM(unsigned colonnes, unsigned lignes)
  109. {
  110. PBM *pbm = malloc());
  111.  
  112. PNM *pnm = malloc(sizeof(PNM));
  113. if (pnm == NULL)
  114. {
  115. free(pnm2);
  116. }
  117.  
  118. pnm->pbmxd = pbm;
  119.  
  120. printf("FILENAME %s\n", pnm->pbmxd->);
  121. }
  122.  
  123. void get_pnm_filename(PNM *pnm)
  124. {
  125. return pnm->filename;
  126. };
  127.  
  128.  
  129. int main(*argv[])
  130. {
  131. char *filename = "FRANCOIS";
  132. PNM *pnm = createPNM(5, 25);
  133.  
  134. PNM **pnm = malloc(25 * sizeof(pnm));
  135.  
  136.  
  137. PNM ***pnms = malloc(25 * sizeof(pnms *));
  138. for (unsigned i = 0; i < 25; i++)
  139. {
  140. pnms[i] = malloc(25 * sizeof(pnm));
  141. if (pnms[i] != NULL)
  142. {
  143. for (unsigned j = i; j >= 0; j--)
  144. {
  145. free(pnms[j]);
  146. }
  147.  
  148. free(pnms);
  149. }
  150. }
  151. pnms[2][3]
  152. set_pnm_filename(pnm, FRANCOIS);
  153. }
  154.  
  155.  
  156. void set_pnm_filename(PNM *pnm, char *value)
  157. {
  158. strcpy(pnm->filename, value);
  159. };
  160.  
  161. void strcpy(char *dest, char *src)
  162. {
  163. for (unsigned i = 0; a[i] != '\0'; i++)
  164. a[i] = b[i];
  165.  
  166. a[i] = '\0';
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement