String mit Umlaute per Parameter übergeben



  • Ich habs mal hier hochgeladen.
    Als Umgebung habe ich extra Codeblocks mit einem uralten gcc genommen (Win 10 x64)...



  • bei mir funktionierts auch

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <Windows.h>
    #include <string.h>
    
    int main(int argc, char *argv[]) {
    	int i;
    	unsigned char search[512];
    
    	for (i = 1; i<argc; i++) {
    
    		if (strncmp(argv[i], "-search", strlen("-search")) == 0) {
    			if (i + 1 != argc) {
    				strncpy(search, argv[i + 1], sizeof(search));
    				printf("search: %s\n", search);
    
    				MessageBox(0, search, search, 0);
    			}
    			else {
    				printf("Keyword for searching is missing. Exit !\n\n");
    				return 1;
    			}
    		}
    	}
    }
    


  • Danke für eure Mühen.
    Habe gerade das Gefühl ich bin bekloppt.

    @yahendrik bei mir zeigt er das 'ü' als ³ an.



  • Folgender Code:

    #include <stdio.h>
    
    int main ()
    {
        char s[] = "öäüß";
        printf ("%s - %d", s, sizeof(s));
    }
    

    Der Editor steht auf UTF-8, gibt mit "Visual Studio" compiliert das aus:

    öäüß - 9
    

    Schalte ich auf Toolchain "Cygwin" um (ist ein GCC), erhalte ich:

    öäüß - 9

    Was sagt uns das?

    Der String ist 9 Bytes groß, also in beiden Fällen (jeweils 2 Byte pro Zeichen und eine 0 am Ende, eben UTF-8.

    Je nach Toolchain wird aber offensichtlich ein anderes "printf" verwendet. Die CygWin-Variante kann mit UTF-8 umgehen, die des "Visual Studio" offenbar nicht. 😞



  • Die erste Ausgabe hat das Forum noch mal zusätzlich vergurkt.
    Es sind 4 kryptische Zeichen, aber trotzdem nicht das was man sehen will.



  • wie sagt man? meine glaskugel ist mir neulich herunter gefallen und irgendwie dauert das ewig, bis man sie mal repariert hat, und das pendel ist sich auch sehr unschlüssig.

    könntest du daher einmal ein paar infos (compiler, programmcode, debug-informationen, sonstige evtl. wichtig erscheinende dinge) liefern?



  • Wade1234 schrieb:

    wie sagt man? meine glaskugel ist mir neulich herunter gefallen und irgendwie dauert das ewig, bis man sie mal repariert hat, und das pendel ist sich auch sehr unschlüssig.

    könntest du daher einmal ein paar infos (compiler, programmcode, debug-informationen, sonstige evtl. wichtig erscheinende dinge) liefern?

    Als IDE benutze ich CLion, der Editor steht auf UTF-8 (wie gesagt). Ich kann die Toolchain umschalten. Dann wird mit CMake ein neues Makefile generiert mit dem der Testcode gebaut wird.

    CMake erzeugt folgenden Output by CygWin:

    C:\Users\Administrator\.CLion2017.3\system\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /cygdrive/c/Users/Administrator/ClionProjects/untitled2
    -- The C compiler identification is GNU 5.4.0
    -- The CXX compiler identification is GNU 5.4.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++.exe
    -- Check for working CXX compiler: /usr/bin/c++.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /cygdrive/c/Users/Administrator/ClionProjects/untitled2/cmake-build-debug
    

    Das generierte Cygwin-Makefile ist das

    # CMAKE generated file: DO NOT EDIT!
    # Generated by "Unix Makefiles" Generator, CMake Version 3.9
    
    # Default target executed when no arguments are given to make.
    default_target: all
    
    .PHONY : default_target
    
    # Allow only one "make -f Makefile2" at a time, but pass parallelism.
    .NOTPARALLEL:
    
    #=============================================================================
    # Special targets provided by cmake.
    
    # Disable implicit rules so canonical targets will work.
    .SUFFIXES:
    
    # Remove some rules from gmake that .SUFFIXES does not remove.
    SUFFIXES =
    
    .SUFFIXES: .hpux_make_needs_suffix_list
    
    # Suppress display of executed commands.
    $(VERBOSE).SILENT:
    
    # A target that is always out of date.
    cmake_force:
    
    .PHONY : cmake_force
    
    #=============================================================================
    # Set environment variables for the build.
    
    # The shell in which to execute make rules.
    SHELL = /bin/sh
    
    # The CMake executable.
    CMAKE_COMMAND = /cygdrive/c/Users/Administrator/.CLion2017.3/system/cygwin_cmake/bin/cmake.exe
    
    # The command to remove a file.
    RM = /cygdrive/c/Users/Administrator/.CLion2017.3/system/cygwin_cmake/bin/cmake.exe -E remove -f
    
    # Escaping for special characters.
    EQUALS = =
    
    # The top-level source directory on which CMake was run.
    CMAKE_SOURCE_DIR = /cygdrive/c/Users/Administrator/ClionProjects/untitled2
    
    # The top-level build directory on which CMake was run.
    CMAKE_BINARY_DIR = /cygdrive/c/Users/Administrator/ClionProjects/untitled2/cmake-build-debug
    
    #=============================================================================
    # Targets provided globally by CMake.
    
    # Special rule for the target edit_cache
    edit_cache:
    	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
    	/cygdrive/c/Users/Administrator/.CLion2017.3/system/cygwin_cmake/bin/cmake.exe -E echo No\ interactive\ CMake\ dialog\ available.
    .PHONY : edit_cache
    
    # Special rule for the target edit_cache
    edit_cache/fast: edit_cache
    
    .PHONY : edit_cache/fast
    
    # Special rule for the target rebuild_cache
    rebuild_cache:
    	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
    	/cygdrive/c/Users/Administrator/.CLion2017.3/system/cygwin_cmake/bin/cmake.exe -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
    .PHONY : rebuild_cache
    
    # Special rule for the target rebuild_cache
    rebuild_cache/fast: rebuild_cache
    
    .PHONY : rebuild_cache/fast
    
    # The main all target
    all: cmake_check_build_system
    	$(CMAKE_COMMAND) -E cmake_progress_start /cygdrive/c/Users/Administrator/ClionProjects/untitled2/cmake-build-debug/CMakeFiles /cygdrive/c/Users/Administrator/ClionProjects/untitled2/cmake-build-debug/CMakeFiles/progress.marks
    	$(MAKE) -f CMakeFiles/Makefile2 all
    	$(CMAKE_COMMAND) -E cmake_progress_start /cygdrive/c/Users/Administrator/ClionProjects/untitled2/cmake-build-debug/CMakeFiles 0
    .PHONY : all
    
    # The main clean target
    clean:
    	$(MAKE) -f CMakeFiles/Makefile2 clean
    .PHONY : clean
    
    # The main clean target
    clean/fast: clean
    
    .PHONY : clean/fast
    
    # Prepare targets for installation.
    preinstall: all
    	$(MAKE) -f CMakeFiles/Makefile2 preinstall
    .PHONY : preinstall
    
    # Prepare targets for installation.
    preinstall/fast:
    	$(MAKE) -f CMakeFiles/Makefile2 preinstall
    .PHONY : preinstall/fast
    
    # clear depends
    depend:
    	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
    .PHONY : depend
    
    #=============================================================================
    # Target rules for targets named untitled2
    
    # Build rule for target.
    untitled2: cmake_check_build_system
    	$(MAKE) -f CMakeFiles/Makefile2 untitled2
    .PHONY : untitled2
    
    # fast build rule for target.
    untitled2/fast:
    	$(MAKE) -f CMakeFiles/untitled2.dir/build.make CMakeFiles/untitled2.dir/build
    .PHONY : untitled2/fast
    
    main.o: main.c.o
    
    .PHONY : main.o
    
    # target to build an object file
    main.c.o:
    	$(MAKE) -f CMakeFiles/untitled2.dir/build.make CMakeFiles/untitled2.dir/main.c.o
    .PHONY : main.c.o
    
    main.i: main.c.i
    
    .PHONY : main.i
    
    # target to preprocess a source file
    main.c.i:
    	$(MAKE) -f CMakeFiles/untitled2.dir/build.make CMakeFiles/untitled2.dir/main.c.i
    .PHONY : main.c.i
    
    main.s: main.c.s
    
    .PHONY : main.s
    
    # target to generate assembly for a file
    main.c.s:
    	$(MAKE) -f CMakeFiles/untitled2.dir/build.make CMakeFiles/untitled2.dir/main.c.s
    .PHONY : main.c.s
    
    # Help Target
    help:
    	@echo "The following are some of the valid targets for this Makefile:"
    	@echo "... all (the default if no target is provided)"
    	@echo "... clean"
    	@echo "... depend"
    	@echo "... edit_cache"
    	@echo "... rebuild_cache"
    	@echo "... untitled2"
    	@echo "... main.o"
    	@echo "... main.i"
    	@echo "... main.s"
    .PHONY : help
    
    #=============================================================================
    # Special targets to cleanup operation of make.
    
    # Special rule to run CMake to check the build system integrity.
    # No rule that depends on this can have commands that come from listfiles
    # because they might be regenerated.
    cmake_check_build_system:
    	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
    .PHONY : cmake_check_build_system
    

    Und für Visual Studio der CMake-Output:

    "C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" C:\Users\Administrator\ClionProjects\untitled2
    -- The C compiler identification is MSVC 19.10.25017.0
    -- The CXX compiler identification is MSVC 19.10.25017.0
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/Administrator/ClionProjects/untitled2/cmake-build-debug
    

    und das generierte Makefile für VS ist das

    # CMAKE generated file: DO NOT EDIT!
    # Generated by "NMake Makefiles" Generator, CMake Version 3.9
    
    # Default target executed when no arguments are given to make.
    default_target: all
    
    .PHONY : default_target
    
    # Allow only one "make -f Makefile2" at a time, but pass parallelism.
    .NOTPARALLEL:
    
    #=============================================================================
    # Special targets provided by cmake.
    
    # Disable implicit rules so canonical targets will work.
    .SUFFIXES:
    
    .SUFFIXES: .hpux_make_needs_suffix_list
    
    # Suppress display of executed commands.
    $(VERBOSE).SILENT:
    
    # A target that is always out of date.
    cmake_force:
    
    .PHONY : cmake_force
    
    #=============================================================================
    # Set environment variables for the build.
    
    !IF "$(OS)" == "Windows_NT"
    NULL=
    !ELSE
    NULL=nul
    !ENDIF
    SHELL = cmd.exe
    
    # The CMake executable.
    CMAKE_COMMAND = "C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe"
    
    # The command to remove a file.
    RM = "C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe" -E remove -f
    
    # Escaping for special characters.
    EQUALS = =
    
    # The top-level source directory on which CMake was run.
    CMAKE_SOURCE_DIR = C:\Users\Administrator\ClionProjects\untitled2
    
    # The top-level build directory on which CMake was run.
    CMAKE_BINARY_DIR = C:\Users\Administrator\ClionProjects\untitled2\cmake-build-debug
    
    #=============================================================================
    # Targets provided globally by CMake.
    
    # Special rule for the target edit_cache
    edit_cache:
    	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
    	echo >nul && "C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe" -E echo "No interactive CMake dialog available."
    .PHONY : edit_cache
    
    # Special rule for the target edit_cache
    edit_cache\fast: edit_cache
    
    .PHONY : edit_cache\fast
    
    # Special rule for the target rebuild_cache
    rebuild_cache:
    	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
    	echo >nul && "C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
    .PHONY : rebuild_cache
    
    # Special rule for the target rebuild_cache
    rebuild_cache\fast: rebuild_cache
    
    .PHONY : rebuild_cache\fast
    
    # The main all target
    all: cmake_check_build_system
    	$(CMAKE_COMMAND) -E cmake_progress_start C:\Users\Administrator\ClionProjects\untitled2\cmake-build-debug\CMakeFiles C:\Users\Administrator\ClionProjects\untitled2\cmake-build-debug\CMakeFiles\progress.marks
    	$(MAKE) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) all
    	$(CMAKE_COMMAND) -E cmake_progress_start C:\Users\Administrator\ClionProjects\untitled2\cmake-build-debug\CMakeFiles 0
    .PHONY : all
    
    # The main clean target
    clean:
    	$(MAKE) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) clean
    .PHONY : clean
    
    # The main clean target
    clean\fast: clean
    
    .PHONY : clean\fast
    
    # Prepare targets for installation.
    preinstall: all
    	$(MAKE) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) preinstall
    .PHONY : preinstall
    
    # Prepare targets for installation.
    preinstall\fast:
    	$(MAKE) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) preinstall
    .PHONY : preinstall\fast
    
    # clear depends
    depend:
    	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 1
    .PHONY : depend
    
    #=============================================================================
    # Target rules for targets named untitled2
    
    # Build rule for target.
    untitled2: cmake_check_build_system
    	$(MAKE) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) untitled2
    .PHONY : untitled2
    
    # fast build rule for target.
    untitled2\fast:
    	$(MAKE) -f CMakeFiles\untitled2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\untitled2.dir\build
    .PHONY : untitled2\fast
    
    main.obj: main.c.obj
    
    .PHONY : main.obj
    
    # target to build an object file
    main.c.obj:
    	$(MAKE) -f CMakeFiles\untitled2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\untitled2.dir\main.c.obj
    .PHONY : main.c.obj
    
    main.i: main.c.i
    
    .PHONY : main.i
    
    # target to preprocess a source file
    main.c.i:
    	$(MAKE) -f CMakeFiles\untitled2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\untitled2.dir\main.c.i
    .PHONY : main.c.i
    
    main.s: main.c.s
    
    .PHONY : main.s
    
    # target to generate assembly for a file
    main.c.s:
    	$(MAKE) -f CMakeFiles\untitled2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\untitled2.dir\main.c.s
    .PHONY : main.c.s
    
    # Help Target
    help:
    	@echo The following are some of the valid targets for this Makefile:
    	@echo ... all (the default if no target is provided)
    	@echo ... clean
    	@echo ... depend
    	@echo ... untitled2
    	@echo ... edit_cache
    	@echo ... rebuild_cache
    	@echo ... main.obj
    	@echo ... main.i
    	@echo ... main.s
    .PHONY : help
    
    #=============================================================================
    # Special targets to cleanup operation of make.
    
    # Special rule to run CMake to check the build system integrity.
    # No rule that depends on this can have commands that come from listfiles
    # because they might be regenerated.
    cmake_check_build_system:
    	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0
    .PHONY : cmake_check_build_system
    

    ======================================================================

    Der C-Code bleibt gleich, es gibt auch keine versteckten #defines oder #pragmas.

    Die Konsole die den Output des C-Programms zeigt, ist die eingebaute Konsole von CLion. Sie steht die ganze Zeit auch auf UTF-8 und der Font wird auch nicht verändert.

    Dass einer der Compiler vor dem Build die ZeichenCodierung von UTF-8 in etwas anderes ändert, halte ich für unwahrscheinlich.

    Wenn nicht verschiedene Printfs der Grund ist, was dann?



  • Noch ein Versuch: start aus cmd.exe

    codepage ist 437 (default)
    mit vs-compilierter code: wirre zeichen
    mit cygwin compilierter code: korrekt

    dann codepage auf 65001 umgeschaltet
    mit vs-compilierter code: korrekt
    mit cygwin compilierter code: korrekt

    Seltsam?! In der Tat. Ich kapiere es nicht. 😞



  • Ich habe mir jetzt mal die einzelnen Bytes des Strings "öäüß"; anzeigen lassen.
    Sie sind immer: c3 b6 c3 a4 c3 bc c3 9f 0
    bei beiden Compilern.

    Es bleibt nur der Schluss, dass der CygWin-Code die Codepage erkennt und dann ein Character-Mapping macht. Denn mit Codepage 437 sind "öäüß" ebenfalls möglich.

    Sehe ich das richtig?



  • CharCodingTester schrieb:

    Es bleibt nur der Schluss, dass der CygWin-Code die Codepage erkennt und dann ein Character-Mapping macht. Denn mit Codepage 437 sind "öäüß" ebenfalls möglich.

    Sehe ich das richtig?

    Oder das die cygwin runtime die codepage der console auf UTF-8 setzt wenn das programm gestartet wird.



  • ich habe dir doch oben ein programm geschrieben (kriegt du sonst bestimmt auch so hin, aber wegen copy paste), dass sämtliche zeichen ausgibt.

    vergleich die ausgaben mal und du wirst bestimmt feststellen, dass sie unterschiedlich sind, womit wir dann wieder beim ausgangspunkt sind, dass umlaute bzw. zeichen ab 128 nicht genormt sind, jeder machen kann, was er will, und man deshalb darauf verzichten sollte.

    oder du rufst am anfang system("chcp 65001") auf und hast dann eben die entsprechenden nachteile. 🙄



  • Nutze VS 2010.
    Habe mal bisschen rumgetestet, lese ich Umlaute über fgets von stdin ein dann bekomme ich den String mit Umlauten richtig angezeigt.

    Also ich habe keine Möglichkeit mit Parameterübergabe mit Strings die Umlaute enthalten zu arbeiten ?



  • naja du könntest unicode verwenden und die daten dann über pipes an das programm übergeben.



  • Oder mal

    setlocale(LC_ALL, ".65001"));
    

    am Anfang des (VS) Programms aufrufen.


Anmelden zum Antworten