2
/**
5. Faça um programa que receba 2 strings (A e B) e
retorne uma terceira string (C) formada pelos caracteres de A e B intercalados.
Ex.: Se A='Quarta' e B='Segunda', a resposta deve ser 'QSueagrutnada'
**/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main(){
char s1[30], s2[30], s3[60];
int i=0, tamanho=0;
printf("String 1: ");
scanf(" %s", s1);
printf("String 2: ");
scanf(" %s", s2);
tamanho = strlen(s1) + strlen(s2);
for(i; i < tamanho; i++){
if(s3[i]%2 == 0){
s3[i] = s1[i];
}else{
s3[i] = s2[i];
}
}
printf(" %s", s3);
}
The pro result I’ve done so far is this, I thought - I’ll concatenate a letter in the even position and another letter in the odd position but in logic it didn’t look like I imagined
I know in C I learned about function strcat()
, but I don’t know how to apply in this example.
It is a pity that the code has the problems I was talking about in https://answall.com/a/213923/101. If I give a more idiomatic answer, even if not the one you want, just for reference to other people of a better code.
– Maniero
@bigown College addiction, they taught me this way and it’s how I’m charged there :d
– WSS
That is, I’m discouraging you. People who don’t understand C teaching C.
– Maniero
@bigown Unfortunately..
– WSS