C++ Template-Metaprogramming, 160 154 116 bytes
Just for the giggles.
Thanks to ex-bart for golfing it down!
template<int w,int x,int y,int...s>class A:A<w+(x==y),x,s...>{};A<0,'t','t','t','t','g','g','l','o','y','o','i',0>a;
Usage:
The first char in the template instanciation is the character to search.
Complile with clang -std=c++11 -c -> the result is at the beginning of the error message.
Occurences.cpp:1:66: error: too few template arguments for class template 'A'
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
^
Occurences.cpp:1:66: note: in instantiation of template class 'A<3, 't', '\x00'>' requested here
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
Complile with gcc -std=c++11 -c -> the result is at the bottom of the error message.
Occurences.cpp: In instantiation of ‘const int A<3, 't', '\000'>::a’:
Occurences.cpp:1:64: recursively required from ‘const int A<1, 't', 't', 't', 'g', 'g', 'l', 'o', 'y', 'o', 'i', '\000'>::a’
Occurences.cpp:1:64: required from ‘const int A<0, 't', 't', 't', 't', 'g', 'g', 'l', 'o', 'y', 'o', 'i', '\000'>::a’
Occurences.cpp:2:62: required from here
Occurences.cpp:1:64: error: wrong number of template arguments (2, should be at least 3)
Search for the A<3, 't', '\000'> and A<3, 't', '\x00'>
154 byte version
template<int w,char x,char y,char...s>class A{static const int a=A<w+(x==y),x,s...>::a;};
int a=A<0,'t','t','t','t','g','g','l','o','y','o','i','\0'>::a;
160 byte version:
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
int a=A<0,'t','t','t','t','g','g','l','o','y','o','i','\0'>::a;
11This seems almost too easy of a challenge. Also why limit the input to 10, instead of no limit at all? – Fatalize – 2015-09-02T09:37:28.613
7Needs a winning condition. – isaacg – 2015-09-02T09:41:20.753
2Feel free to rollback my edit if it doesn't agree with you – Beta Decay – 2015-09-02T10:13:23.977
8How flexible is the input format? Can we choose a different delimiter, like a space or newline? Can the string be in quotes? Can we take the letter first and the string second? Will the characters always be lower case letters? If not, which other characters can occur? – Martin Ender – 2015-09-02T10:50:41.923
1@DigitalTrauma I think the OP posted the question and just took off, so if we have any questions, we're probably going to edit in the answers – Beta Decay – 2015-09-02T18:54:36.620
@BetaDecay fair enough - I only just looked at your edit - you made substantial quality improvements. – Digital Trauma – 2015-09-02T18:59:25.637
1The OP didn't specify that functions are allowed. He just said write a program. – mbomb007 – 2015-09-02T19:56:21.670
5This looks suspiciously like a C interview question... – Quentin – 2015-09-02T20:33:36.303
Also posted on GeeksforGeeks Q&A: Create a program that asks the user to input 10 letters..
– manatwork – 2015-09-03T07:37:34.753@manatwork Good find. This question might be a problem if content on that site is under a restrictive license. – Alex A. – 2015-09-03T16:20:58.230
1@Quentin Let's hope they were smart enough to use the shortest solution in their interview. ;) – ThisSuitIsBlackNot – 2015-09-03T19:35:35.430