Ver Mensaje Individual
  #7 (permalink)  
Antiguo 28/10/2014, 08:58
Avatar de Profesor_Falken
Profesor_Falken
 
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: Concatenar punteros char

Aqui va mi superconcatenator de cadenas

Código C:
Ver original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.   int i = 0;
  7.   const char *str1 = "Esto es un test ";
  8.   const char *str2 = "de concatenacion";
  9.  
  10.   char *str3 = malloc(strlen(str1) + strlen(str2) + 1);
  11.  
  12.   while(*str1){
  13.       str3[i++]=*str1++;
  14.   }
  15.   while(*str2){
  16.       str3[i++]=*str2++;
  17.   }
  18.   str3[i]='\0';
  19.  
  20.   printf("%s\n", str3);
  21.  
  22.   free(str3);
  23.  
  24.   return 0;
  25. }
__________________
If to err is human, then programmers are the most human of us