How to design a C function that shortens a string to 8 characters in C Programming Language ?
Solution:
- #include "base.h"
- #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;
- }
Learn More :
Characters
- C Program Character toupper() Example
- C Program Character Example
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Copy One Character Array Into Another
- C Program to Print ASCII equivalent of a character until terminated by key is ‘x’
- C Program to find the number of unique characters
- Printing ASCII Table with Numbers and corresponding characters
- C Program to Compare Two Character
- Menu driven program in C which performs the following operations on strings
- File Handling (console to file) in C Program
String
- Write a c program to check given string is palindrome number or not.
- C Program to Convert Text String to Binary
- C Program String - Alphabet Count Example
- C Program String Example
- C Program String Count Example
- C Program String Example
- C Program to Print a String Without Use Semicolon.
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Print String In Formatted Output Form
- C Program To Reverse The String Using Pointer
- C Program Concatenating Two Strings Into A Third System
- C Program Date from string DDDD-DD-DD
- BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL
- C Program Finds Sub-String Search in String
- C Program to concatenate two strings without using string functions
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to convert a string to upper case
- C Program Performs a search and replace for a specified target and replacement string
- C Program Anagrams
- C Program to find string length without library function
- C Program to Check Given String is Palindrome or Not
- C Program to Converts a Number to a String.
Function
- How to pass one dimensional array to function in c.
- Write a c program which passes two dimension array to function.
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program Character toupper() Example
- C Program Function Example
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program To Convert Temperature In Celsius To Fahrenheit, Using Function
- C Program To Find Simple Interest
- C Function to Check Vowel
- Factorial Program In C Using Function
- C Program For Prime Number Using Function
- C Function to xorSwap and addSwap in C Programming
- C Program to concatenate two strings without using string functions
- C Function to read instructions from the file and obey them
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to Implements a dictionary's functionality.
- = (int*)malloc(sizeof(int)) ??
- C Program to Implements a dictionary's functionality
- C Program that prompts the user to input a string, (whitespaces allowed)
- Local sounds functions in C Program
- Function Get the resource that will be gathered from the zone name
- C Program to Find the Size of File using File Handling Function
- Average function in C
Design
Shorten