/*********************************************************************** * Copyright (C) 2022 Prosource (CLI Systems LLC) * https://prosource.dev * * License: * THIS SOURCE CODE IS PART OF THE prosource.dev EMBEDDED SYSTEM * KNOWLEDGE-BASE. This source code is a Free Solution as defined * in the Prosource Usage License and is provided under the * Creative Commons Attribution 4.0 International (CC BY 4.0) license * as defined at https://creativecommons.org/licenses/by/4.0/ * * This source code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED * ***********************************************************************/ #include #include #include int _fwrite(char *str, int len) { while(*str && len--) { putchar(*str); str++; } return len; } void test(int v) { char output[40]; printf("\nTesting:\n"); sprintf(output,"testing '%d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%ld'\n",v*-1); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%ld'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%lld'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%08d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%00d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '% 8d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%.8d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%_8d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%?8d'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%lu'\n",v*-1); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%lu'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%llu'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%08u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%00u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '% 8u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%.8u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%_8u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing '%?8u'\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%x\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%08x\n",v*-1); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%08x\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x% 8x\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%.8x\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%_8x\n",v); _fwrite(output,strlen(output)+1); sprintf(output,"testing 0x%?8x\n",v); _fwrite(output,strlen(output)+1); } int main(int argc,char ** argv) { printf("Running\n"); test(1); test(-1); test(123); test(-123); test(-1147483646); test(0x123); test(2147483646); test(0x7fffffff); test(4294967295); //test(100000000000); //test(0x100000000000); printf("This is a float test %f\n",-0.0); printf("This is a float test %f\n",0.00); printf("This is a float test %f\n",42); printf("This is a float test %f\n",-42); printf("This is a float test %f\n",1.234); printf("This is a float test %f\n",12345.678); printf("This is a float test %f\n",-12345.678); printf("This is a %s\n","test"); printf("This is a %c test\n",'!'); printf("This is a %c test\n",241); printf("This is a %c test\n",184); printf("This is another %% %s\n","test"); return 0; }