-
Code char *fanis(const char *input, int value) { char *r = malloc(strlen(input) + 1), *p = r; while (*input) *p++ = *input++ + value; return *p = '\0', r; }
Test Cases char *fanis(const char *input, int value); void basic_test(const char *input, int value, const char *expected) { char *submited = fanis(input, value); cr_assert_str_eq(submited, expected); free(submited); } Test(the_multiply_function, should_pass_all_the_tests_provided) { basic_test("123", 2, "345"); basic_test("472", 1, "583"); }
Output:
-
Code - #include <stdlib.h>
- #include <string.h>
char *fanis(char *r, int k) {char *w = malloc(strlen(r) + 1), *p = w;while(w && *r) *p++ = k + *r++;return w;- char *fanis(const char *input, int value)
- {
- char *r = malloc(strlen(input) + 1), *p = r;
- while (*input) *p++ = *input++ + value;
- return *p = '\0', r;
- }
Test Cases - #include <criterion/criterion.h>
- char *fanis(const char *input, int value);
Test(the_multiply_function, should_pass_all_the_tests_provided) {cr_assert_str_eq(fanis("123", 2), "345");- void basic_test(const char *input, int value, const char *expected)
- {
- char *submited = fanis(input, value);
- cr_assert_str_eq(submited, expected);
- free(submited);
- }
- Test(the_multiply_function, should_pass_all_the_tests_provided)
- {
- basic_test("123", 2, "345");
- basic_test("472", 1, "583");
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}