Skip to content

Instantly share code, notes, and snippets.

@radiofreejohn
Created March 12, 2011 23:31
Show Gist options
  • Save radiofreejohn/867696 to your computer and use it in GitHub Desktop.
Save radiofreejohn/867696 to your computer and use it in GitHub Desktop.
K&R Exercise 5-5, strncat
#include <stdio.h>
void strnfeline(char *s, const char *t, int n);
void strnfeline(char *s, const char *t, int n)
{
//this is bad if s is not terminated
while(*++s)
;
while(n--)
*s++ = *t++;
*s = '\0';
}
int main()
{
char glee[40] = "Glee is";
char quality[] = " badass";
strnfeline(glee, quality, 4);
printf("%s\n", glee);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment