Enviado em 15/07/2015 - 21:23h
Boa noite à todos;
#include <stdio.h>
#include <string.h>
int main ()
{
/* a variável "str" salva a string concatenada;
* as variáveis "str1", ..., "str4" salvam a
* 1ª, a 2ª, a 3ª e a 4ª strings (fornecidas
* pelo usuário), respectivamente */
char str[100], str1[100], str2[100], str3[100], str4[100];
/* as próximas linhas lêem as strings: */
printf ("\n\nDigite a 1ª string: ");
fgets (str1, 100, stdin);
printf ("\nDigite a 2ª string: ");
fgets (str2, 100, stdin);
printf ("\nDigite a 3ª string: ");
fgets (str3, 100, stdin);
printf ("\nDigite a 4ª string: ");
fgets (str4, 100, stdin);
/* as próximas linhas concatenam as strings na var. "str" */
strcat (str, str1);
strcat (str, str2);
strcat (str, str3);
strcat (str, str4);
/* imprime a variável concatenada */
printf ("\n\n%s\n", str);
return(0);
}
#include <stdio.h>
#include <string.h>
int main ()
{
int count;
char str[100], str1[100], str2[100], str3[100], str4[100];
printf ("\n\nDigite a 1ª string: ");
fgets (str1, 100, stdin);
for (count = 0; count < strlen(str1); count++)
{
str[count]=str1[count];
if (count == (strlen(str1) - 1))
{
str[count + 1]=' ';
str[count + 2]='\0';
}
}
strcpy (str1, str);
strcpy (str, "");
printf ("\nDigite a 2ª string: ");
fgets (str2, 100, stdin);
for (count = 0; count < strlen(str2); count++)
{
str[count]=str2[count];
if (count == (strlen(str2) - 1))
{
str[count + 1]=' ';
str[count + 2]='\0';
}
}
strcpy(str2, str);
strcpy (str, "");
printf ("\nDigite a 3ª string: ");
fgets (str3, 100, stdin);
for (count = 0; count < strlen(str3); count++)
{
str[count]=str3[count];
if (count == (strlen(str3) - 1))
{
str[count + 1]=' ';
str[count + 2]='\0';
}
}
strcpy (str3, str);
strcpy (str, "");
printf ("\nDigite a 4ª string: ");
fgets (str4, 100, stdin);
for (count = 0; count < strlen(str4); count++)
{
str[count]=str4[count];
if (count == (strlen(str4) - 1))
{
str[count + 1]=' ';
str[count + 2]='\0';
}
}
strcpy (str4, str);
strcpy (str, "");
strcat (str3, str4);
strcat (str2, str3);
strcat (str1, str2);
strcat (str, str1);
printf ("\n\n%s\n", str);
return(0);
}