How search within the first N bytes of the block of memory with memchr() function in C

3 Answers

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

int main(void)
{
	char *p;
	char s[] = "C Programming IDE";
	
	p = (char *) memchr(s, 'm', strlen(s));
	if (p != NULL)
		printf("%s\n", p);
	else
		printf("'m' not found\n");
	
	return 0;
}

 
/*
   
run:
   
mming IDE

*/

 



answered Jan 26, 2016 by avibootz
edited Jan 26, 2016 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

int main(void)
{
	char *p;
	char s[] = "C Programming IDE";
	
	p = (char *) memchr(s, 'm', 5);
	if (p != NULL)
		printf("%s\n", p);
	else
		printf("'m' not found\n");
	
	return 0;
}

 
/*
   
run:
   
'm' not found

*/

 



answered Jan 26, 2016 by avibootz
edited Jan 26, 2016 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

int main(void)
{
	char *p;
	char s[] = "C Programming IDE";
	
	p = (char *) memchr(s, 'm', strlen(s));
	if (p != NULL)
		printf("Found at position : %ld\n", p - s);
	else
		printf("'m' not found\n");
	
	return 0;
}

 
/*
   
run:
   
Found at position : 8

*/

 



answered Jan 26, 2016 by avibootz

Related questions

1 answer 115 views
115 views asked Apr 23, 2023 by avibootz
2 answers 135 views
135 views asked Dec 16, 2022 by avibootz
1 answer 193 views
193 views asked Dec 26, 2020 by avibootz
1 answer 235 views
...