mirror of
https://github.com/cc65/cc65.git
synced 2024-11-17 09:07:32 +00:00
2503a31938
git-svn-id: svn://svn.cc65.org/cc65/trunk@188 b7a2c559-68d2-44c3-8de9-860c34a00d81
60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* Test string. Must NOT have duplicate characters! */
|
|
static char S[] = "Helo wrd!\n";
|
|
|
|
static char Found[256];
|
|
|
|
|
|
|
|
int main (void)
|
|
{
|
|
unsigned Len;
|
|
unsigned I;
|
|
char* P;
|
|
|
|
/* Print a header */
|
|
printf ("strchr(): ");
|
|
|
|
/* Get the length of the string */
|
|
Len = strlen (S);
|
|
|
|
/* Search for all characters in the string, including the terminator */
|
|
for (I = 0; I < Len+1; ++I) {
|
|
|
|
/* Search for this char */
|
|
P = strchr (S, S[I]);
|
|
|
|
/* Check if we found it */
|
|
if (P == 0 || (P - S) != I) {
|
|
printf ("Failed for code 0x%02X, offset %u!\n", S[I], I);
|
|
printf ("P = %04X offset = %04X\n", P, P-S);
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
|
|
/* Mark the char as checked */
|
|
Found[S[I]] = 1;
|
|
}
|
|
|
|
/* Search for all other characters and make sure they aren't found */
|
|
for (I = 0; I < 256; ++I) {
|
|
if (Found[I] == 0) {
|
|
if (strchr (S, (char)I) != 0) {
|
|
printf ("Failed for code 0x%02X\n", I);
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Test passed */
|
|
printf ("Passed\n");
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
|
|
|