You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
833 B

/**
* :author: Dan Buch (daniel.buch@gmail.com)
*/
#include <stdio.h>
void duff(register char *to, register char *from, register int count)
{
register int n;
int remainder = count % 8;
if (remainder == 0) {
n = (count + 7) / 8;
do {
*to++ = *from++;
} while (--n > 0);
} else if (remainder <= 7 && remainder > 0) {
int i;
int c;
for (i = 0; (c = from[i] && c != EOF); i++) {
to[i] = c;
}
}
}
int main()
{
char * to = "dogs cats babies";
char * from = "monkey hat pants";
int i = 11;
printf("to = %s\n", to);
printf("from = %s\n", from);
/* And here comes the segfault... */
duff(to, from, i);
printf("to = %s\n", to);
printf("from = %s\n", from);
}
/* vim:filetype=c:fileencoding=utf-8
*/