A side note on your problem: returning 1 on success and 0 on failure is not the standard function behavior in C literature (aside from functions returning a boolean). Are you following a guide or a course?
You should not arbitrarily pre-allocate 250 chars for your strings. Strings are most often represented by char pointers, handled with dynamic memory allocation. I understand that gets() takes a pre-allocated buffer, but this is a really bad practice. You should consider using the fgets() function and use its maximum number of characters argument for a better security. Hard-coding string length is also hard to maintain (multiple places to modify the length) as well as confusing for readers (it's not clear if the compiler will pass the argument by copy or by reference).
Also, don't try to hide your code. The line containing the strncpy()
have two statements, with the unary star pending in-between the two, looking like a multiplication operator. Don't do such things. Put the second statement on a new line.
That being said, you also misunderstood the arguments from the strncpy
function: it is destination first, followed by source. You copy an uninitialized buffer (strcopy) into your string. Note that you also misinterpret the value of your temp
variable which returns an error when something went well. It also returns 0 instead of 1 as asked.
Last notice: you really should break;
your for-loop in your function formatString()
, otherwise your strncpy will be executed for every \0
in your string.
I would recommend to check for exercises in a book if you are self-taught or seek the assistance of a TA if you are following a course. They will be able to guide you in the right path for understanding your mistakes.