strrchr() - return 0 when you search '\0' char
:sample test code
char * ptr;
char testString = "hello";
ptr = strrchr( testString, '\0' );
*(ptr - 1) = '~';
Expected output : hell~ (Tested and works on standard libraries on windows and Linux)
Actual output:hello. (On KEIL, Not ok)
IDE-Version:µVision V220.127.116.11Copyright (C) 2019 ARM Ltd and ARM Germany GmbH. All rights reserved.
Tool Version Numbers:Toolchain: MDK Professional 5.28 (Flex) Version: 18.104.22.168Toolchain Path: C:\Keil_MDK528a\ARM\ARMCC\BinC Compiler: Armcc.exe V5.06 update 6 (build 750)Assembler: Armasm.exe V5.06 update 6 (build 750)Linker/Locator: ArmLink.exe V5.06 update 6 (build 750)Library Manager: ArmAr.exe V5.06 update 6 (build 750)Hex Converter: FromElf.exe V5.06 update 6 (build 750)CPU DLL: SARMCM3.DLL V22.214.171.124Dialog DLL: TCM.DLL V126.96.36.199Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V188.8.131.52Dialog DLL: TCM.DLL V184.108.40.206
My guess is that you are using microlib.
Microlib is not compliant with the C library standard. Some features are not supported and some are supported with reduced functionality.
strrchr seems to be implemented in the microlib with reduced functionality.
If you don't use microlib, strrchr will behave as you expect. If you do use microlib, strrchr has the issue that it cannot be used to find the end of a string.
View all questions in Keil forum