Advertisement
FamiHug

cpy

Jun 9th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. /*
  2.  * =====================================================================================
  3.  *
  4.  *       Filename:  cpy.c
  5.  *
  6.  *    Description:  
  7.  *
  8.  *        Version:  1.0
  9.  *        Created:  06/10/2011 09:39:13 AM
  10.  *       Revision:  none
  11.  *       Compiler:  gcc
  12.  *
  13.  *         Author:  FamiHug (fh), famihug@gmail.com
  14.  *        Company:  familug.blogspot.com
  15.  *
  16.  * =====================================================================================
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. void NhapMaTran(float **matrix)
  24. {
  25.     int size = 3;
  26.     int i,j;
  27.  
  28.     *matrix =  (float *)malloc(size * (size + 1) * sizeof(float));
  29.  
  30.     printf("Nhap vao ma tran: \n");
  31.     for(i = 0; i < 3; i++)
  32.     {
  33.         for(j = 0; j < 4; j++)
  34.         {
  35.             scanf("%f",*matrix + i * (size + 1)  + j);
  36.         }
  37.     }
  38.     printf("Nhap xong!\n");
  39.     return;
  40. }
  41.  
  42. void InRaMatran(float **matrix)
  43. {
  44.     int size = 3;
  45.     int i,j;
  46.  
  47.     printf("Ma Tran: \n");
  48.     for(i = 0; i < size; i++)
  49.     {
  50.         for(j = 0; j < size + 1; j++)
  51.         {
  52.             printf("%3.3f ",*(*matrix + i * (size + 1) + j));
  53.         }
  54.         printf("\n");
  55.     }
  56.     return;
  57. }
  58.  
  59. void copyMatran(float **matrix, float **q)
  60. {
  61.     memcpy(q,matrix,sizeof(float) * 3 * 4);
  62. }
  63.  
  64. int main()
  65. {
  66.     float *p, *q;
  67.     q = (float *)malloc(sizeof(float) * 3 * 4);
  68.     NhapMaTran(&p);
  69.     InRaMatran(&p);
  70.     copyMatran(&p,&q);
  71.  
  72.     InRaMatran(&q);
  73.  
  74. //
  75. //  memcpy(cp,c,strlen(c) + 1);
  76. //  int i;
  77. //  for(i = 0; i < 4; i++)
  78. //  {
  79. //      printf("%d ",cp[i]);
  80. //  }
  81. //
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement