Whoops, rounded means aren't very usefulm0skit0 wrote:Wrong, the average is not correctly calculated and shown. Average could be a decimal. You're rounding it down using int.
[spoiler]
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char* s1 = "New\nLine\n";
char* s2 = "Another string!";
char* s4 = "And another string.";
char* s5 = "Yet another string.";
char s3[100];
strcpy(s3, s1);
strcat(s3, s2);
strcat(s3, s4);
strcat(s3, s5);
unsigned int len_s3 = strlen(s3);
float x = len_s3;
float y = 4;
float z = x / y;
printf("%s and the length is: %u\n",s3 , len_s3);
printf("The average length of these four strings is: %f\n", z);
return 0;
}Right, I was thinking that seemed too easy to be right. This took me a while, but it seems good now.m0skit0 wrote:Wrong. The program should be able to handle any string.
[spoiler]
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char* s1 = ("I am me, you are you.");
char s2[20];
int s1len = strlen(s1); //string 1 length
int ssmelen = strlen(strstr(s1, "me")); //sub string "me" length
strncpy(s2, s1, s1len - ssmelen); //copy characters equal to the difference of s1len and ssmelen
strcat(s2, "me");
printf("%s\n",s2);
return 0;
}

