Created
August 26, 2014 12:30
-
-
Save Pompeu/8a2ca11d453eb65d532a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
char* combina(char *a, char *b); | |
int main(){ | |
int n; | |
scanf("%i ",&n);//esse espaço logo depois do %i limpa o buffer | |
char a[51],b[51]; | |
while(n--){ | |
scanf("%s",a); | |
scanf("%s",b); | |
printf("%s\n",combina(a,b)); | |
} | |
return 0; | |
} | |
/* essa função faz duas "Strings" se juntarem | |
*/ | |
char* combina(char *a, char *b){ | |
int tam = 0;//contador do tanho do primeiro vetor de char | |
char *r = (char*)malloc(sizeof(char)+1*103);//aloco o tamanho maximo dos dois vetores de char +1 para o '\0' | |
for (int i = 0; *a != '\0'; i++){ | |
r[i] = *a++; | |
tam++; | |
} | |
//inicio o i com tanho do primeiro vetor | |
for (int i = tam; *b != '\0'; i++){ | |
r[i] = *b++; | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment