Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- char * a_to_u(char txt[]);
- char * u_to_a(char txt[]);
- int main(int argc, char *argv[]) {
- if (argc != 2) {
- printf("Invalid arguments");
- return 0;
- }
- FILE *fp;
- char path[100];
- char text[5000];
- printf("Insert file path: ");
- scanf("%[^\n]s", path);
- fp = fopen(path, "r");
- if (fp) {
- fgets(text, 1024, fp);
- text[strlen(text)] = '\0';
- } else {
- printf("An error occurred while opening the file.\n");
- }
- fclose(fp);
- char *mod;
- if (strcmp(argv[1], "-a") == 0)
- mod = a_to_u(text);
- else if (strcmp(argv[1], "-u") == 0)
- mod = a_to_u(text);
- else
- printf("Invalid arguments");
- return 0;
- fp = fopen(path, "w");
- if (fp) {
- fprintf(fp, mod);
- } else {
- printf("An error occurred while opening the file.\n");
- }
- fclose(fp);
- }
- char * a_to_u(char txt[]) {
- std::string str(txt);
- if (str.empty())
- return char{};
- int size_needed = MultiByteToWideChar(CP_ACP, 0, &str[0], (int)str.size(), NULL, 0);
- std::wstring wstr(size_needed, 0);
- MultiByteToWideChar(CP_ACP, 0, &str[0], (int)str.size(), &wstr[0], size_needed);
- size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
- std::string strTo(size_needed, 0);
- WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
- strcpy(txt, strTo.c_str());
- return txt;
- }
- char * u_to_a(char txt[]) {
- std::string str(txt);
- if (str.empty())
- return char{};
- int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
- std::wstring wstr(size_needed, 0);
- MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size_needed);
- size_needed = WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
- std::string strTo(size_needed, 0);
- WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
- strcpy(txt, strTo.c_str());
- return txt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement