[ create a new paste ] login | about

Link: http://codepad.org/VcDo1QPC    [ raw code | output | fork ]

nel - C, pasted on Oct 16:
// memcpy alternative

#include <stdio.h>
#include <string.h>

void* memcpyX(char* dest, const char* source, size_t num);

int main(void)
{
	char str[] = "Now let's see if memcpyX() function works correctly.";
	char str2[80];

	memcpyX(str2, str, strlen(str)+1);

	printf("Str [1] content: %s", str);
	printf("\nStr [2] content: %s", str2);

    printf("\n\nDone?!");
}

void* memcpyX(char* dest, const char* source, size_t num)
{
	while(num) { // while num is positive
		*dest++=*source++;
		num--;
	}
}


Output:
1
2
3
4
5
Str [1] content: Now let's see if memcpyX() function works correctly.
Str [2] content: Now let's see if memcpyX() function works correctly.

Done?!
Exited: ExitFailure 8


Create a new paste based on this one


Comments: