C Programming Language

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.dev
1242

Suggest improvements to my IPv4 ping census program

11d 14h ago by infosec.pub/u/sacred_font in c_lang@programming.dev from github.com
873

Is this a limitation of scanf() or bad control flow?

17d 10h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
874

The electronics/logic behind "while(1)" and "for(;;)

22d 11h ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
865

Why 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.dev
346

Aesthetics: goto or not

1mon 2d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
677

THANK YOU ALL!!! - what errors should I check for and handle?

1mon 7d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
1048

Does an "if - else" statement always need the "else"?

1mon 10d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
9119

Lessons 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
5210

[Beginner] How do I save previous input in variables/arrays?

1mon 14d ago by piefed.blahaj.zone/u/akunohana in c_lang@programming.dev
8811

input handling in c

4mon 6d ago by lemmy.zip/u/14th_cylon in c_lang@programming.dev
1412

six thoughts on generating c

4mon 8d ago by europe.pub/u/cm0002 in c_lang@programming.dev from wingolog.org
2013

Modern Tools for Hunting Undefined Behavior in C

4mon 16d ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from slicker.me
9214

GNU C Library 2.43 released

4mon 22d ago by no.lastname.nz/u/cm0002 in c_lang@programming.dev from sourceware.org
5015

Best Practices for Ownership in GLib

4mon 27d ago by libretechni.ca/u/cm0002 in c_lang@programming.dev from blog.sebastianwick.net
3016

Copying values pointed to by addresses stored in two variables (confusion with pointers).

4mon 29d ago by programming.dev/u/iliketurtiles in c_lang@programming.dev
7317

How can I force the entry-point to be at start of .text?

4mon 2h ago by programming.dev/u/iliketurtiles in c_lang@programming.dev
9418

C-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.com
1019

Help needed!

5mon 25d ago by lemmy.zip/u/yris_latteyi in c_lang@programming.dev
151720

Performance Hints

5mon 1h ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from abseil.io
8021

The Cost Of a Closure in C

6mon 8d ago by lemmy.world/u/monica_b1998 in c_lang@programming.dev from thephd.dev
3022

The Cost Of a Closure in C

6mon 8d ago by programming.dev/u/CodiUnicorn in c_lang@programming.dev from thephd.dev
10023

Why I write games in C

7mon 27d ago by programming.dev/u/snikta in c_lang@programming.dev from jonathanwhiting.com
10124

GNU Tools Cauldron 2025

8mon 4d ago by programming.dev/u/snikta in c_lang@programming.dev from conf.gnu-tools-cauldron.org
3025

Code snippet archive?

8mon 26d ago by lemmy.ml/u/TruePe4rl in c_lang@programming.dev
4426

Fil-C

9mon 15d ago by programming.dev/u/snikta in c_lang@programming.dev from fil-c.org
8027

The GNU C Library version 2.42 is now available

10mon 23d ago by lemmy.world/u/cm0002 in c_lang@programming.dev from sourceware.org
4028

Async‑signal-safety and why should you care

10mon 29d ago by programming.dev/u/Serpent7776 in c_lang@programming.dev from dev.to
8029

C is one of the most energy saving language

1y 11d ago by lemmy.world/u/chimay in c_lang@programming.dev
13730

guile on whippet waypoint: goodbye, bdw-gc? — wingolog

1y 1mon ago by lemmy.ml/u/greywolf0x1 in c_lang@programming.dev from wingolog.org
4031

The Defer Technical Specification: It Is Time

1y 3mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from thephd.dev
9032

Time 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.com
4133

Any good cheat sheets about C?

1y 8mon ago by snac.bsd.cafe/modev in c_lang@programming.dev
25734

Few lesser known tricks, quirks and features of C

1y 8mon ago by discuss.tchncs.de/u/captainkangaroo in c_lang@programming.dev from jorenar.com
14035

Flappy Bird for Android, only C, under 100KB

1y 8mon ago by discuss.tchncs.de/u/captainkangaroo in c_lang@programming.dev from github.com
20036

ACBS - Another C Build System

1y 9mon ago by programming.dev/u/KindaABigDyl in c_lang@programming.dev
8637

Getting back into C programming for CP/M

1y 9mon ago by lemmy.ndlug.org/u/pnutzh4x0r in c_lang@programming.dev from kevinboone.me
17238

Writing 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.com
28539

ISO/IEC DIS 9899: Project cancelled

1y 11mon ago by programming.dev/u/cmeerw in c_lang@programming.dev from www.iso.org
8241

researchrsc: On Duff's Device and Coroutines

1y 11mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from research.swtch.com
6042

The C Standard charter (2024)

1y 11mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from www.open-std.org
8043

UB 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.uk
13044

A 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.com
19145

One year of C (2018)

2y 1mon ago by programming.dev/u/lysdexic in c_lang@programming.dev from floooh.github.io
22046

Blackjack 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.com
5047

Improvements 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.com
10048

GCC 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.com
26549

How to write a good C main function

2y 2mon ago by programming.dev/u/akrz in c_lang@programming.dev from opensource.com
16050