[Solved] delete all digits except one

Just to show you current C++ (C++20) works a bit different then wat most (older) C++ material teaches you. #include <algorithm> #include <iostream> #include <string> #include <ranges> bool is_not_four(const char digit) { return digit != ‘4’; } int main() { // such a big number iwll not fit in any of the integer types // … Read more

[Solved] how to display the statistics about all the files in a folder in C# [closed]

Look at this: “How to: Get Information About Files, Folders, and Drives (C# Programming Guide)” http://msdn.microsoft.com/en-us/library/6yk7a1b0.aspx For example: // Get the files in the directory and print out some information about them. System.IO.FileInfo[] fileNames = dirInfo.GetFiles(“*.*”); foreach (System.IO.FileInfo fi in fileNames) { Console.WriteLine(“{0}: {1}: {2}”, fi.Name, fi.LastAccessTime, fi.Length); } You can change the Console.WriteLine to … Read more

[Solved] SEGFAULT on strcpy

void findErrors(int lineIndex){ char *line; strcpy(line, lines[lineIndex]); //^ this is undefined behaviour. At that point line is not initialized and strcopying something to a non initialized pointer results in undefined behaviour, usually a segfault. But if by chance line points to some valid memory, the program may not crash and it may look as if … Read more

[Solved] how is an header file implemented say an string.h file [closed]

Header files normally only contains prototype declarations of methods, just to satisfy initial compiler checks. The implementation files are already compiled to binary forms and distributed as library files. They are linked to your program during the linking process. If you have studied C, you will remember that you used to add a prototype declaration … Read more

[Solved] Access static property in another class’s non-static constructor in c# [closed]

Instead of: class MyClass { private int _value; public MyClass() { _value = OtherClass.StaticInt; } } Favour: class MyClass { private int _value; public MyClass(int valueForConstruction) { _value = valueForConstruction; } } Decouples MyClass from OtherClass, even if you do this: MyClass c = new MyClass(OtherClass.StaticInt); 2 solved Access static property in another class’s non-static … Read more

[Solved] 3-3. Write a program to count how many times each distinct word appears in its input

If you can’t use std::map, you can associate the word with the frequency: struct Info { std::string word; int frequency; }; //… std::vector<Info> database; //… std::string word; while (std::cin >> word) { // Find the word: const size_t length = database.size(); for (unsigned int i = 0; i < length; ++i) { if (database[i].word == … Read more