Quite a while ago, my friend had a task to write a program which would count how many words does a text contain. He was unsure how to tackle the problem. He wasn’t allowed to use any system function. He had to write all of the code by himself. As I love problems, I decided to do it for him.
The code is written in C# although he had to write in C.
static void Main(string[] args) { char[] polje; string recenica = ""; string path = "C:\\Users\\some\\Desktop\\sample_file.txt"; try { StreamReader str = new StreamReader(path); int counter = 0; while (!str.EndOfStream) { recenica = str.ReadLine(); Console.WriteLine(recenica); polje = recenica.ToCharArray(); for (int i = 0; i = 97 && (int)polje2[index + 1] = 64 && (int)polje2[index + 1] = 32 && (int)polje2[index] = 58 && (int)polje2[index] <= 64)) { return true; } return false; }