Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System; // Console
- using System.IO; // FileStream, FileReader
- class FileDetails
- {
- // Подсчет гласных, согласных и строк
- public static void Summarize(char[] contents)
- {
- int vowel = 0, notvowel = 0, count = 1;
- foreach (char symbol in contents)
- {
- if ("AEIOUaeiou".IndexOf(symbol) != -1)
- vowel++;
- else
- notvowel++;
- if (symbol == '\r')
- count++;
- }
- Console.WriteLine("Vowels:{0}\nNon-vowels: {1}\nStrings: {2} \nOverall count: {3}", vowel, notvowel, count, vowel + notvowel);
- }
- static void Main(string[] args)
- {
- // Имя файла
- string filename;
- Console.WriteLine("Arguments count: {0}", args.Length);
- //foreach (string arg in args)
- // Console.ReadLine(arg);
- try
- {
- if (args.Length == 1) // Если есть аргумент
- {
- // Передаем аргумент в имя файла и открываем поток
- filename = args[0];
- FileStream stream = new FileStream(filename, FileMode.Open);
- StreamReader reader = new StreamReader(stream);
- // Вычисляем длину файла
- int length = Convert.ToInt32(stream.Length);
- // Создаем массив для текста и копируем текст из файла
- char[] contents = new char[length];
- for (int i = 0; i < length; i++)
- contents[i] = Convert.ToChar(reader.Read());
- reader.Close(); // Закрываем поток
- // Вывод результата
- Console.WriteLine(contents);
- Summarize(contents);
- Console.WriteLine("Complete.");
- };
- }
- // Обработка исключения (если файл с таким именем не найден)
- catch (FileNotFoundException)
- {
- Console.WriteLine("File not found.");
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement