#include "string.h"
/*
Design a function that shortens a string to 8 characters.
*/
// String -> String
String truncate(String string);
void truncate_test() {
check_expect_s(truncate("1234567891011"), "12345678"); // line 19
check_expect_s(truncate("123"), "123"); // line 20
check_expect_s(truncate("12345678"), "12345678"); // line 21
}
// Returns the original string or shortens it to the first 8 characters.
String truncate(String string) {
if (s_length(string) <= 8) {
return(string);
} else {
return(s_sub(string, 0,8));
}
return 0;
}
int main(void) {
truncate_test();
return 0;
}
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.