Advertisement
jacknpoe

Código para Criando bibliotecas em C

Jul 20th, 2015
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. __________________________________________________________________________________________________________
  2.  
  3. INICIAL.C
  4. __________________________________________________________________________________________________________
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. void troca_int( int *valor1, int *valor2);
  11. void troca_float( float *valor1, float *valor2);
  12.  
  13. int main( void) {
  14.     int int1 = 200, int2 = 100;
  15.     float pf1 = 2.5, pf2 = 1.5;
  16.     troca_int( &int1, &int2);
  17.     troca_float( &pf1, &pf2);
  18.     printf( "Int1: %i, int2: %i, pf1: %f, pf2: %f\n\n", int1, int2, pf1, pf2);
  19.     system( "PAUSE");
  20.     return 0;
  21. }
  22.  
  23. void troca_int( int *valor1, int *valor2) {
  24.     int temp;
  25.     temp = *valor1;
  26.     *valor1 = *valor2;
  27.     *valor2 = temp;
  28. }
  29.  
  30. void troca_float( float *valor1, float *valor2) {
  31.     float temp;
  32.     temp = *valor1;
  33.     *valor1 = *valor2;
  34.     *valor2 = temp;
  35. }
  36.  
  37. __________________________________________________________________________________________________________
  38.  
  39. TROCA.C
  40. __________________________________________________________________________________________________________
  41.  
  42.  
  43. #include "troca.h"
  44.  
  45. void troca_int( int *valor1, int *valor2) {
  46.     int temp;
  47.     temp = *valor1;
  48.     *valor1 = *valor2;
  49.     *valor2 = temp;
  50. }
  51.  
  52. void troca_float( float *valor1, float *valor2) {
  53.     float temp;
  54.     temp = *valor1;
  55.     *valor1 = *valor2;
  56.     *valor2 = temp;
  57. }
  58.  
  59.  
  60. __________________________________________________________________________________________________________
  61.  
  62. TROCA.H
  63. __________________________________________________________________________________________________________
  64.  
  65.  
  66. #ifndef TROCA_HEADER_
  67. #define TROCA_HEADER_
  68.  
  69. void troca_int( int *valor1, int *valor2);
  70. void troca_float( float *valor1, float *valor2);
  71.  
  72. #endif
  73.  
  74. __________________________________________________________________________________________________________
  75.  
  76. TESTE.C
  77. __________________________________________________________________________________________________________
  78.  
  79.  
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include "troca.h"
  83.  
  84. int main( void) {
  85.     int int1 = 200, int2 = 100;
  86.     float pf1 = 2.5, pf2 = 1.5;
  87.     troca_int( &int1, &int2);
  88.     troca_float( &pf1, &pf2);
  89.     printf( "Int1: %i, int2: %i, pf1: %f, pf2: %f\n\n", int1, int2, pf1, pf2);
  90.     system( "PAUSE");
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement