Free Photos
WordPress Themes

Code for counting chars in string

#include<stdio.h> #include<string.h> int countA(char *x) { int count = 0; char *px = x; char tocount; scanf_s("%c", &tocount); while (*px != '\0') { if (*px == tocount) count++; px++; } return count; } int main() { char x[30]; gets(x); int num; num=countA(x); printf("%d", num); system("PAUSE"); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.