Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/05/2011, 10:49
_Lx
 
Fecha de Ingreso: mayo-2011
Mensajes: 17
Antigüedad: 13 años
Puntos: 11
Busqueda Respuesta: Como puedo retornar 2 valores con una funcion

Hice esto, veremos si te ayuda ...

Código C:
Ver original
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. char* funcion();
  5.  
  6. int main()
  7. {
  8.    char* A;
  9.    
  10.    A = funcion();
  11.    
  12.    printf("\nLos valores son: %c, %c y %c\n", A[0], A[1], A[2]);
  13.    
  14.    free(A);  // Libera el espacio de memoria ocupado por A
  15.    while( getchar()!='\n');  // Libera la basura del buffer.
  16.    printf("\nPresione ENTER para salir . . .");
  17.    getchar();
  18.    return 0;
  19. }
  20.  
  21. char* funcion()
  22. {
  23.    char a, b, c;
  24.    
  25.    scanf("%c %c %c", &a, &b, &c);
  26.    
  27.    char V[3] = { a, b, c};
  28.    char *ptr = V;
  29.    
  30.    return ptr;
  31. }

Nos vemos .

Última edición por _Lx; 21/05/2011 a las 10:55