Create a function for string-shrinking - C String

C examples for String:String Function

Description

Create a function for string-shrinking

Demo Code


#include <stdio.h>
#include <string.h> /* contains string function prototypes */

void fit(char *, unsigned int);

int main(void){
    char mesg[] = "Things should be as simple as possible,"
                  " but not simpler.";
    //from w  w  w. j ava 2  s  .  com
    puts(mesg);
    fit(mesg,8);
    puts(mesg);
    puts(mesg + 9);
    
    return 0;
}

void fit(char *string, unsigned int size){
    if (strlen(string) > size)
        string[size] = '\0';
}

Result


Related Tutorials