Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to implement the memset function in C

1 Answer

0 votes
#include <stdio.h>

void* memset(void* s, int c, size_t n) {
	// copy c into s from s to s + n
	const unsigned char ch = c;
	unsigned char* str = (unsigned char*)s;

	for (; 0 < n; str++, n--)
		*str = ch;
	return s;
}

int main() {
	char str[32] = "c programming";

	memset(str + 2, '*', 6);

	puts(str);

    return 0;
}




/*
run:
    
c ******mming
    
*/

 



answered Dec 17, 2022 by avibootz

Related questions

1 answer 89 views
89 views asked Nov 11, 2022 by avibootz
1 answer 103 views
103 views asked May 29, 2024 by avibootz
1 answer 149 views
5 answers 182 views
182 views asked Nov 11, 2022 by avibootz
1 answer 59 views
59 views asked Jun 10, 2025 by avibootz
1 answer 114 views
...