shithub: scc

ref: b655b713cf6cb7abb87ef704b3dc24f91d7b2b3e
dir: /tests/libc/execute/0012-strchr.c/

View raw version
#include <assert.h>
#include <stdio.h>
#include <string.h>

/*
output:
testing
done
end:
*/

int
main()
{
	char *p, buf[] = "abcad";

	puts("testing");

	p = strchr(buf, 0);
	assert(p == buf+5);
	assert(*p == '\0');

	p = strchr(buf, 'a');
	assert(p == buf);
	assert(*p == 'a');

	p = strchr(buf, 'd');
	assert(p == buf+4);
	assert(*p == 'd');

	p = strchr(buf, 'c');
	assert(p == buf+2);
	assert(*p == 'c');

	p = strchr(buf, 'h');
	assert(p == NULL);

	p = strchr("", 'a');
	assert(p == NULL);

	puts("done");

	return 0;
}