
Environment\
Compiler Clang on Termux on Samsung's One UI 7 on a Samsung Galaxy Tab A9+
The title is an assumption on it's own, so feel free to correct it/me!
I was experimenting with sanitizing user input, read to a character array with fgets. Specifically, I was trying to have a for loop remove (skip) certain input. Here is the code:
for (n = strlen(input) - 1; n >= 0; n--) { if (input[n] >= 0x30 && input[n] <= 0x39 || input[n] == ' ' || input[n] == '\t') { input[n] = 0x18; } }
While the program does behave as I want it to, I don't understand why it seemlingy by default understands that the various hex codes refer to the character encoding as per the ASCII table. I cated my tablet's filesystem encoding at /sys/fs/f2fs/dm-44/encoding, which yielded UTF-8. If I understand it correctly, the first 128 code points of Unicode are the same as ASCII's. But according to this article on Wikipedia, there are no hexadecimal references in Unicode, only octal and decimal.
If the underlying filesystem uses UTF-8, and Unicode code points are not referred to by hex, how then does my compiler (Clang) understand what ASCII code points I'm referring to?
Is there some conversion going on under the hood that I am not aware of? I did find a libxml2/libxml/encoding.h, which contains comments about some conversion to and from UTF-8. Is this it? I can't make head or tails of it because of my limited C knowledge...
I C (and most other languages) you can enter a value like thirty-two using many different number bases: ‘ ‘ as a char, 32 in decimal, 0x20 is hex, 040 in octal or 0b00010000. All of these mean thirty-two, just written differently using different characters.
Note that each of these representations use different digits and/or letters to specify the same number - the mathematical entity thirty-two. These letters and digits are characters stored as numbers, eg the digit zero (0) is coded in ASCII as 48.
In the end, the C compiler will compile the text ‘32’, ‘0x40’ or ‘0b00010000’ into binary and store it in memory the single byte where the 5th bit set to 1 and the others to 0. This is the way computer memory is used to represent the number, and it’s linked to the way the electric circuits do things like add numbers together.
The compiler is the thing that understands that the characters like ‘3’, ‘+’ or ‘F’ and works out what they represent (a number, a variable name or a sum). When it understands that, it will turn the code into bits that the CPU can work with, for example passing it to the compare instruction CMP used to test whether the input is less than the number thirty-two.
This is very meta, and I hope this clarifies rather than confuses. Compilers are notoriously confusing, such as the thought ‘the compiler compiles the compiler code into an executable that can compile itself’.
Where do I find the code of standardized functions?
11d 10h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devSuggest improvements to my IPv4 ping census program
11d 14h ago by infosec.pub/u/sacred_font in c_lang@programming.dev from github.comIs this a limitation of scanf() or bad control flow?
17d 10h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devThe electronics/logic behind "while(1)" and "for(;;)
22d 11h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devWhy do some functions return to main() with a newline, even though I am using getchar() to get rid of it?
28d 5h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devAesthetics: goto or not
1mon 2d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devTHANK YOU ALL!!! - what errors should I check for and handle?
1mon 7d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devDoes an "if - else" statement always need the "else"?
1mon 10d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devLessons of "== 0/1/EOF" versus "!= 0/1/EOF" and scanf() versus getchar() in while loops
1mon 12d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev[Beginner] How do I save previous input in variables/arrays?
1mon 14d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.devinput handling in c
4mon 6d ago by lemmy.zip/u/14th_cylon in c_lang@programming.devsix thoughts on generating c
4mon 8d ago by europe.pub/u/cm0002 in c_lang@programming.dev from wingolog.orgModern Tools for Hunting Undefined Behavior in C
4mon 16d ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from slicker.meGNU C Library 2.43 released
4mon 22d ago by no.lastname.nz/u/cm0002 in c_lang@programming.dev from sourceware.orgBest Practices for Ownership in GLib
4mon 27d ago by libretechni.ca/u/cm0002 in c_lang@programming.dev from blog.sebastianwick.netCopying values pointed to by addresses stored in two variables (confusion with pointers).
4mon 29d ago by programming.dev/u/iliketurtiles in c_lang@programming.devHow can I force the entry-point to be at start of .text?
4mon 2h ago by programming.dev/u/iliketurtiles in c_lang@programming.devC-Chronicles-The-Quest-of-Quantum-Code: A C language game for programming beginners
5mon 11d ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from github.comHelp needed!
5mon 25d ago by lemmy.zip/u/yris_latteyi in c_lang@programming.devPerformance Hints
5mon 1h ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from abseil.ioThe Cost Of a Closure in C
6mon 8d ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from thephd.devThe Cost Of a Closure in C
6mon 8d ago by programming.dev/u/CodiUnicorn in c_lang@programming.dev from thephd.devWhy I write games in C
7mon 27d ago by programming.dev/u/snikta in c_lang@programming.dev from jonathanwhiting.comGNU Tools Cauldron 2025
8mon 4d ago by programming.dev/u/snikta in c_lang@programming.dev from conf.gnu-tools-cauldron.orgCode snippet archive?
8mon 26d ago by lemmy.ml/u/TruePe4rl in c_lang@programming.devThe GNU C Library version 2.42 is now available
10mon 23d ago by lemmy.world/u/cm0002 in c_lang@programming.dev from sourceware.orgAsync‑signal-safety and why should you care
10mon 29d ago by programming.dev/u/Serpent7776 in c_lang@programming.dev from dev.toC is one of the most energy saving language
1y 11d ago by lemmy.world/u/chimay in c_lang@programming.devguile on whippet waypoint: goodbye, bdw-gc? — wingolog
1y 1mon ago by lemmy.ml/u/greywolf0x1 in c_lang@programming.dev from wingolog.orgThe Defer Technical Specification: It Is Time
1y 3mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from thephd.devTime to make C the COBOL of this century (The Register - Opinion)
1y 3mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from www.theregister.comAny good cheat sheets about C?
1y 8mon ago by snac.bsd.cafe/modev in c_lang@programming.devFew lesser known tricks, quirks and features of C
1y 8mon ago by discuss.tchncs.de/u/captainkangaroo in c_lang@programming.dev from jorenar.comFlappy Bird for Android, only C, under 100KB
1y 8mon ago by discuss.tchncs.de/u/captainkangaroo in c_lang@programming.dev from github.comACBS - Another C Build System
1y 9mon ago by programming.dev/u/KindaABigDyl in c_lang@programming.devGetting back into C programming for CP/M
1y 9mon ago by lemmy.ndlug.org/u/pnutzh4x0r in c_lang@programming.dev from kevinboone.meWriting a game the hard way - from scratch using C.
1y 9mon ago by slrpnk.net/u/ProdigalFrog in c_lang@programming.dev from www.youtube.comWriting a C Compiler | Build a Real Programming Language from Scratch | Nora Sandler | July 2024 | No Starch Press | 792 pages | ISBN-13: 9781718500426
1y 10mon ago by programming.dev/u/ericjmorey in c_lang@programming.dev from nostarch.comISO/IEC DIS 9899: Project cancelled
1y 11mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from www.iso.orgresearchrsc: On Duff's Device and Coroutines
1y 11mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from research.swtch.comThe C Standard charter (2024)
1y 11mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from www.open-std.orgUB or not UB: How gcc and clang handle statically known undefined behaviour
1y 11mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from diekmann.ukA History of C Compilers - Part 1: Performance, Portability and Freedom
2y 1mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from thechipletter.substack.comOne year of C (2018)
2y 1mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from floooh.github.ioBlackjack game as a learning experience - Request for suggestions, ways to make it better, advice etc...
2y 2mon ago by iusearchlinux.fyi/u/promitheas in c_lang@programming.dev from github.comImprovements to static analysis in the GCC 14 compiler | Red Hat Developer
2y 2mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from developers.redhat.comGCC 14 Boasts Nice ASCII Art For Visualizing Buffer Overflows
2y 2mon ago by lemmy.ml/u/ylai in c_lang@programming.dev from www.phoronix.comHow to write a good C main function
2y 2mon ago by programming.dev/u/akrz in c_lang@programming.dev from opensource.com














