[ create a new paste ] login | about

Link: http://codepad.org/R0gBeLyA    [ raw code | output | fork ]

nel - C, pasted on Oct 16:
// size_t strcspn ( const char * str1, const char * str2 );

#include <stdio.h>

size_t strcspnX(const char *str, const char *keys);

int main(void)
{
	char str[] = "There snow on the mountain, and fog in the street.";
	char keys[] = "!,.:;?-";

	unsigned int match = (strcspnX(str, keys))+1;

        printf("First punctuation char is: %d", match);

	return 0;
}

size_t strcspnX(const char *str, const char *keys)
{
        char *temp;
	unsigned i_temp = 0;

	for(str; *str!='\0'; str++, i_temp++) {
                
                temp=keys; // initialize temp* point to &keys[0]
 
		while(*temp!='\0') {
                   printf("if str [%c] == temp[%c] => i_temp [%d]\n", *str, *temp, i_temp);
                   if(*str==*temp) return i_temp;
                   *temp++;
		}  
	}

	return 0;
}


Output:
if str [T] == temp[!] => i_temp [0]
if str [T] == temp[,] => i_temp [0]
if str [T] == temp[.] => i_temp [0]
if str [T] == temp[:] => i_temp [0]
if str [T] == temp[;] => i_temp [0]
if str [T] == temp[?] => i_temp [0]
if str [T] == temp[-] => i_temp [0]
if str [h] == temp[!] => i_temp [1]
if str [h] == temp[,] => i_temp [1]
if str [h] == temp[.] => i_temp [1]
if str [h] == temp[:] => i_temp [1]
if str [h] == temp[;] => i_temp [1]
if str [h] == temp[?] => i_temp [1]
if str [h] == temp[-] => i_temp [1]
if str [e] == temp[!] => i_temp [2]
if str [e] == temp[,] => i_temp [2]
if str [e] == temp[.] => i_temp [2]
if str [e] == temp[:] => i_temp [2]
if str [e] == temp[;] => i_temp [2]
if str [e] == temp[?] => i_temp [2]
if str [e] == temp[-] => i_temp [2]
if str [r] == temp[!] => i_temp [3]
if str [r] == temp[,] => i_temp [3]
if str [r] == temp[.] => i_temp [3]
if str [r] == temp[:] => i_temp [3]
if str [r] == temp[;] => i_temp [3]
if str [r] == temp[?] => i_temp [3]
if str [r] == temp[-] => i_temp [3]
if str [e] == temp[!] => i_temp [4]
if str [e] == temp[,] => i_temp [4]
if str [e] == temp[.] => i_temp [4]
if str [e] == temp[:] => i_temp [4]
if str [e] == temp[;] => i_temp [4]
if str [e] == temp[?] => i_temp [4]
if str [e] == temp[-] => i_temp [4]
if str [ ] == temp[!] => i_temp [5]
if str [ ] == temp[,] => i_temp [5]
if str [ ] == temp[.] => i_temp [5]
if str [ ] == temp[:] => i_temp [5]
if str [ ] == temp[;] => i_temp [5]
if str [ ] == temp[?] => i_temp [5]
if str [ ] == temp[-] => i_temp [5]
if str [s] == temp[!] => i_temp [6]
if str [s] == temp[,] => i_temp [6]
if str [s] == temp[.] => i_temp [6]
if str [s] == temp[:] => i_temp [6]
if str [s] == temp[;] => i_temp [6]
if str [s] == temp[?] => i_temp [6]
if str [s] == temp[-] => i_temp [6]
if str [n] == temp[!] => i_temp [7]
if str [n] == temp[,] => i_temp [7]
if str [n] == temp[.] => i_temp [7]
if str [n] == temp[:] => i_temp [7]
if str [n] == temp[;] => i_temp [7]
if str [n] == temp[?] => i_temp [7]
if str [n] == temp[-] => i_temp [7]
if str [o] == temp[!] => i_temp [8]
if str [o] == temp[,] => i_temp [8]
if str [o] == temp[.] => i_temp [8]
if str [o] == temp[:] => i_temp [8]
if str [o] == temp[;] => i_temp [8]
if str [o] == temp[?] => i_temp [8]
if str [o] == temp[-] => i_temp [8]
if str [w] == temp[!] => i_temp [9]
if str [w] == temp[,] => i_temp [9]
if str [w] == temp[.] => i_temp [9]
if str [w] == temp[:] => i_temp [9]
if str [w] == temp[;] => i_temp [9]
if str [w] == temp[?] => i_temp [9]
if str [w] == temp[-] => i_temp [9]
if str [ ] == temp[!] => i_temp [10]
if str [ ] == temp[,] => i_temp [10]
if str [ ] == temp[.] => i_temp [10]
if str [ ] == temp[:] => i_temp [10]
if str [ ] == temp[;] => i_temp [10]
if str [ ] == temp[?] => i_temp [10]
if str [ ] == temp[-] => i_temp [10]
if str [o] == temp[!] => i_temp [11]
if str [o] == temp[,] => i_temp [11]
if str [o] == temp[.] => i_temp [11]
if str [o] == temp[:] => i_temp [11]
if str [o] == temp[;] => i_temp [11]
if str [o] == temp[?] => i_temp [11]
if str [o] == temp[-] => i_temp [11]
if str [n] == temp[!] => i_temp [12]
if str [n] == temp[,] => i_temp [12]
if str [n] == temp[.] => i_temp [12]
if str [n] == temp[:] => i_temp [12]
if str [n] == temp[;] => i_temp [12]
if str [n] == temp[?] => i_temp [12]
if str [n] == temp[-] => i_temp [12]
if str [ ] == temp[!] => i_temp [13]
if str [ ] == temp[,] => i_temp [13]
if str [ ] == temp[.] => i_temp [13]
if str [ ] == temp[:] => i_temp [13]
if str [ ] == temp[;] => i_temp [13]
if str [ ] == temp[?] => i_temp [13]
if str [ ] == temp[-] => i_temp [13]
if str [t] == temp[!] => i_temp [14]
if str [t] == temp[,] => i_temp [14]
if str [t] == temp[.] => i_temp [14]
if str [t] == temp[:] => i_temp [14]
if str [t] == temp[;] => i_temp [14]
if str [t] == temp[?] => i_temp [14]
if str [t] == temp[-] => i_temp [14]
if str [h] == temp[!] => i_temp [15]
if str [h] == temp[,] => i_temp [15]
if str [h] == temp[.] => i_temp [15]
if str [h] == temp[:] => i_temp [15]
if str [h] == temp[;] => i_temp [15]
if str [h] == temp[?] => i_temp [15]
if str [h] == temp[-] => i_temp [15]
if str [e] == temp[!] => i_temp [16]
if str [e] == temp[,] => i_temp [16]
if str [e] == temp[.] => i_temp [16]
if str [e] == temp[:] => i_temp [16]
if str [e] == temp[;] => i_temp [16]
if str [e] == temp[?] => i_temp [16]
if str [e] == temp[-] => i_temp [16]
if str [ ] == temp[!] => i_temp [17]
if str [ ] == temp[,] => i_temp [17]
if str [ ] == temp[.] => i_temp [17]
if str [ ] == temp[:] => i_temp [17]
if str [ ] == temp[;] => i_temp [17]
if str [ ] == temp[?] => i_temp [17]
if str [ ] == temp[-] => i_temp [17]
if str [m] == temp[!] => i_temp [18]
if str [m] == temp[,] => i_temp [18]
if str [m] == temp[.] => i_temp [18]
if str [m] == temp[:] => i_temp [18]
if str [m] == temp[;] => i_temp [18]
if str [m] == temp[?] => i_temp [18]
if str [m] == temp[-] => i_temp [18]
if str [o] == temp[!] => i_temp [19]
if str [o] == temp[,] => i_temp [19]
if str [o] == temp[.] => i_temp [19]
if str [o] == temp[:] => i_temp [19]
if str [o] == temp[;] => i_temp [19]
if str [o] == temp[?] => i_temp [19]
if str [o] == temp[-] => i_temp [19]
if str [u] == temp[!] => i_temp [20]
if str [u] == temp[,] => i_temp [20]
if str [u] == temp[.] => i_temp [20]
if str [u] == temp[:] => i_temp [20]
if str [u] == temp[;] => i_temp [20]
if str [u] == temp[?] => i_temp [20]
if str [u] == temp[-] => i_temp [20]
if str [n] == temp[!] => i_temp [21]
if str [n] == temp[,] => i_temp [21]
if str [n] == temp[.] => i_temp [21]
if str [n] == temp[:] => i_temp [21]
if str [n] == temp[;] => i_temp [21]
if str [n] == temp[?] => i_temp [21]
if str [n] == temp[-] => i_temp [21]
if str [t] == temp[!] => i_temp [22]
if str [t] == temp[,] => i_temp [22]
if str [t] == temp[.] => i_temp [22]
if str [t] == temp[:] => i_temp [22]
if str [t] == temp[;] => i_temp [22]
if str [t] == temp[?] => i_temp [22]
if str [t] == temp[-] => i_temp [22]
if str [a] == temp[!] => i_temp [23]
if str [a] == temp[,] => i_temp [23]
if str [a] == temp[.] => i_temp [23]
if str [a] == temp[:] => i_temp [23]
if str [a] == temp[;] => i_temp [23]
if str [a] == temp[?] => i_temp [23]
if str [a] == temp[-] => i_temp [23]
if str [i] == temp[!] => i_temp [24]
if str [i] == temp[,] => i_temp [24]
if str [i] == temp[.] => i_temp [24]
if str [i] == temp[:] => i_temp [24]
if str [i] == temp[;] => i_temp [24]
if str [i] == temp[?] => i_temp [24]
if str [i] == temp[-] => i_temp [24]
if str [n] == temp[!] => i_temp [25]
if str [n] == temp[,] => i_temp [25]
if str [n] == temp[.] => i_temp [25]
if str [n] == temp[:] => i_temp [25]
if str [n] == temp[;] => i_temp [25]
if str [n] == temp[?] => i_temp [25]
if str [n] == temp[-] => i_temp [25]
if str [,] == temp[!] => i_temp [26]
if str [,] == temp[,] => i_temp [26]
First punctuation char is: 27


Create a new paste based on this one


Comments: