Created
March 12, 2011 23:31
-
-
Save radiofreejohn/867696 to your computer and use it in GitHub Desktop.
K&R Exercise 5-5, strncat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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