yifanzhu1592 / C-Primer-Plus-All-Codes

All "Examples Code" in the book "C Primer Plus (6th Edition) (Stephen Prata)"
34 stars 16 forks source link

11.17 Code missing #1

Closed fyqc closed 5 months ago

fyqc commented 3 years ago
#include <stdio.h>
#include <string.h>
void fit(char *, unsigned int);

int main(void)
{
    char mesg[] = "things should be as simple as possible,"
                  " but not simpler.";

    puts(mesg);
    fit(mesg, 38);
    puts(mesg);
    puts("Let's look at some more of the string.");
    puts(mesg + 39);

    return 0;
}

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

Hi there, thank you so much for your reminding fyqc! The code has been added now.