diff --git a/SS2301-03/ss2301-03.cpp b/SS2301-03/ss2301-03.cpp index e69de29..533fe32 100644 --- a/SS2301-03/ss2301-03.cpp +++ b/SS2301-03/ss2301-03.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +bool is_binary(const std::string& filename) { + std::ifstream file(filename, std::ios::binary); + if (!file) { + std::cerr << "Cannot open file: " << filename << std::endl; + return false; + } + + char ch; + while (file.get(ch)) { + // ヌルバイトが含まれている場合はバイナリとみなす + if (ch == 0x00) { + return true; + } + } + + return false; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " ..." << std::endl; + return 1; + } + + for (int i = 1; i < argc; ++i) { + const std::string filename = argv[i]; + if (is_binary(filename)) { + std::cout << filename << ": Binary file" << std::endl; + } else { + std::cout << filename << ": Text file" << std::endl; + } + } + + return 0; +}