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,885 questions

51,811 answers

573 users

How to implement the strchr function in C

1 Answer

0 votes
#include <stdio.h>

char* strchr(const char* s, const char ch) {
	// find first occurrence of ch in s
	for (; *s != ch; s++)
		if (*s == '\0')
			return (NULL);
	return ((char*)s);
}

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

	puts(strchr(str, 'm'));

	return 0;
}





/*
run:
         
mming
      
*/

 



answered Dec 16, 2022 by avibootz

Related questions

1 answer 126 views
1 answer 209 views
209 views asked Jan 11, 2020 by avibootz
1 answer 94 views
94 views asked Aug 16, 2024 by avibootz
1 answer 56 views
56 views asked Jun 10, 2025 by avibootz
1 answer 111 views
...