I need my teacher today to pass the program, I wrote it and here's her code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int sizeRepeats(char *s, int count) //Get repeat str result size
{
if(count <= 1)
return -1;
return (int)strlen(s)*count;
}
char * repeat(char *s, int count, char *dest)
{
if(count <= 1)
return "Error";
for(int i=0; i<count; i++)
strcat(dest, s);
return dest;
}
int main(int argc, char const *argv[])
{
char *str = "Testing";
char buf[sizeRepeats(str, 5)];
printf("'%s'\n", repeat(str, 5, buf));
return 0;
}
Is this a normal release or can you do better and work even faster?