[ create a new paste ] login | about

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

C++, pasted on Sep 21:
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
	char str[256] = "apple,fruit!agenda sweets\0";

	char pchars[] = ",.! "; int count = 0;
	for (int i = 0; str[i] != '\0'; i++)
		if (strchr(pchars,str[i]) || i == 0)
		{
			int k = i+1;
			while (!strchr(pchars,str[k]) && 
				str[k] != '\0') k++; 

			if (str[i+1] == str[k-1]) count++;
		}

	printf("str = %s\ncount = %d\n",str,count);

	return 0;
}


Output:
1
2
str = apple,fruit!agenda sweets
count = 2


Create a new paste based on this one


Comments: