Making a minimalist hex editor in the C Programming Language. The code is just for fun and not suitable for production :) Link to the code: github.com/nir9/welcome/tree/...
Пікірлер: 64
@nirlichtman6 ай бұрын
Interesting points about the behavior of the program: - Reminding that the code is just for fun and not suitable for production and skips many error checking and other checks - If you open a file that is larger than 1024 bytes and save it will discard all the bytes after 1024 since it truncates the file when saving and saves the 1024 byte long buffer - You can use the p and e commands to go beyond the buffer limits and access memory outside of the buffer
@ItsCOMMANDer_6 ай бұрын
For production it would be better to ``` fseek(f, 0,SEEK_END); long lenght = ftell(f); char* buffer = calloc(lenght, sizeof(char)); fseek(f,0,SEEK_SET); ```
@d9h34nu0df6 ай бұрын
Never stop posting videos, your videos are great inspirations and help me come up with ideas for cool projects to do, as well as already helping with a foundation of how logic works
@benhetland5766 ай бұрын
To be pedantic, the scanf on line 31 contains a memory overwrite bug. It should be given a (unsigned int*) but you give it an (unsigned char*).
@metamirasi6 ай бұрын
Very clear and concise purpose und workflow! I look forward to the next videos👋🙌
@N7TWL6 ай бұрын
Nicely done!
@jannatgaoshiqqalb35986 ай бұрын
What kind if books do you recommend us to have a solid understanding of C if we are beginner for C?
@nirlichtman6 ай бұрын
I enjoyed reading the first edition of "Writing Solid Code" by Steve Maguire, it does require some prior knowledge in C and is a little old but generally has great tips. But the best way to learn in my opinion is to just practically write C for projects and work with the manuals as much as you can. (I recommend trying both Linux and Windows programming and learning to work with the man pages and Microsoft win32 api docs)
@AnalogDude_6 ай бұрын
@@nirlichtman win32/64 is death, but doesn't know it yet.
@baranjan69697 күн бұрын
For absolute beginners K&R is also good one.
@silme94176 ай бұрын
suggestion : make a terminal text editor like nano or vim
@N7TWL6 ай бұрын
Have a look at Nir Lichtman's "Minimalist Text Editor" put up about 2 weeks ago.
@benhetland5766 ай бұрын
He's doing the terminal editor the true old style, the line editor! Like MS-DOS's edlin or Unix's ed. It will probably work with Curious Marc's teletype as its "user interface" too 😊
@juliovata91946 ай бұрын
What terminal do you use?
@greybrunix6 ай бұрын
looks like the windows terminal xD Unironically I think this is Windows with a DWM port for the layout
@thatonemailbox6 ай бұрын
@@greybrunix What is a DWN port?
@nirlichtman6 ай бұрын
@@thatonemailbox DWM is a minimalist tiling window manager for X Window System and is one of the projects of the Suckless group, I use a port of this for Windows called dwm-win32
@juliovata91946 ай бұрын
@@nirlichtmanOk I thought it looked like Windows Terminal lol
@naturebc28 күн бұрын
Even if you’re writing code just for fun and not for production you should do it right.
@mattiasevstedt93406 ай бұрын
Since no one else has mentioned it, the reason for the reversed order on the numbers is because of intel based computers being "little endian".
@sanjaybalnad41806 ай бұрын
I am a high level programmer, usually i work with javascript and python. When i see mid and low level code my head gets burst. But i am really interested in c language 😂
@AnalogDude_6 ай бұрын
pretty much every things is based on C/C++, java, perl, etc.
@rafaeldasilvasena93326 ай бұрын
In (buffer, 1, 1024, f), the "1" would be the size of what exactly?
@nirlichtman6 ай бұрын
The size of each item to write/read, for example if you were writing an array of 4 byte integers you could specify the size to be 4 and the count to be the length of the array. In this video I am working with an array of 1 byte characters and so I decided to use 1 in the count - this also causes the function to return the number of bytes written/read.
@arta61836 ай бұрын
@@nirlichtman I know sizeof(char) is a bit redundant but maybe it could make it more readable, also what if a char's size is different on another platform?
@blacklistnr16 ай бұрын
@@arta6183Then you add a disclaimer that this editor does not support quantum computers :)) All computing devices have the notion of a byte(char). It only gets complicated when you want unicode support and run into wchar and multi byte sequences. or if you go above 1 byte(short, int, long) and run into endiannes(byte order) and platform-dependent sizes.
@rafaeldasilvasena93326 ай бұрын
@@nirlichtmanoh, I get it now, thank you
@benhetland5766 ай бұрын
@@arta6183 sizeof(char) is always 1 -- by definition -- regardless of how many bits it contains. The sizeof operator reports the size in number of chars, not in octets or "bytes" that is commonly assumed.
@NullCyan6 ай бұрын
I have always wondered why argv is a pointer of a pointer, why, just why does that "magically" turn into an array of strings?
@ahmedsat47806 ай бұрын
actually array is just a pointer , so when you create a pointer off characters it's a string ( string is an array of characters ) pointer off string is array of strings
@Zeutomehr6 ай бұрын
arrays decay into pointers when passed as function arguments. within a function they were not declared in, they are identical. could you explain what exactly bugs you, maybe I can help you?
@NullCyan6 ай бұрын
@@Zeutomehr so an array is a pointer to a location of the memory with sequential data?
@StefanoTrevisani6 ай бұрын
well because, in the C point of view, an array is simply a contiguos block of memory, and a string is just an array with additional semantics for humans. A CPU does not atomically manipulate entire blocks of memory, but only small "words" (usually 8, 16, 32 or 64 bits): then, to represent a full block of memory, you can use two words, e.g. one representing the starting location of your block of memory (aka a pointer) and one representing its length. You can also use the single word (pointer) that represents its initial location, if you know that the block is ended by a special delimiter value which is not allowed to appear anywhere else inside the block. And in C, sequences (arrays) of characters (strings) are supposed to always terminate with the non-printable NUL character (i.e. the byte 0). Similarly, the NULL pointer (i.e. the word 0) is assumed to be an invalid memory address, hence it can be used to delimit an arrray of pointers. And this is what argv is: just a machine word telling you "hey, I am a pointer to a block of memory, and each word in the block of memory I point to is also a pointer, and the last of them is the NULL pointer. By the way, they are all pointers to blocks of memory where each byte in those blocks is a character, and the last character in them is the NUL character"
@StefanoTrevisani6 ай бұрын
If you wonder why argc exists, I think it is beacuse it is allowed for arguments other than the last one to be actually NULL pointers...
@gabriellevesque21856 ай бұрын
How can you can call a file VIEWER an Editor?
@nirlichtman6 ай бұрын
Since it is also an editor, it has an edit command ('e') that can modify the bytes
@NullCyan6 ай бұрын
also what if the file has more than 1024 characters?
@ahmedsat47806 ай бұрын
it will only deal with the first 1024 of the file and ignore the rest
@NullCyan6 ай бұрын
@@ahmedsat4780 oh ok thanks
@xblxckxpxny10056 ай бұрын
@@ahmedsat4780 That is not totally correct. Yes you can only modify the first 1024 chars, but what is more important os that when you save, the characters that come after the initial 1024 will be discarded. In simple terms: You lose all characters after 1024. Your file: 1024 * 'A' (1024 'A' in a row) and then 10 * 'b' for example So you have 1024 AAAA... and then 10 bbbbbbbbbb When you execute his program and save your hex-edits. you keep your edits in 1024 'A' region. BUT you lose all the 10 bbbbbbbbbb at the end! If I am wrong here please correct me :) But this should be the result, I also tested.
@nirlichtman6 ай бұрын
@@xblxckxpxny1005That is correct, part of why the code is just for fun and not for production :)
@ahmedsat47806 ай бұрын
@@xblxckxpxny1005 i know 😊😊 but I might not be able to express it correctly because English is not my first language thanks for correcting me.
@richardgrosman57986 ай бұрын
Better than a bot 😋
@ItsCOMMANDer_6 ай бұрын
still waiting for minimalist https server 😅
@ZsomborBerki6 ай бұрын
he already did that
@ItsCOMMANDer_6 ай бұрын
no he didnt, he did an https CLIENT and an HTTP server.@@ZsomborBerki
@cozyfog6 ай бұрын
bro uses windows terminal on linux
@myrix_dev6 ай бұрын
he uses wsl, windows sumsystem for linux and yes, there are tiling wms for windows
@pavlovidankmemeovi6 ай бұрын
He's using a windows port of dwm
@cozyfog6 ай бұрын
@@myrix_dev sound cool ig, I knew of the dwm port but lately its been everywhere idk
@kamertonaudiophileplayer8476 ай бұрын
I duplicated the video in Rust. Is anyone interested in?
@nirlichtman6 ай бұрын
That could be interesting, I haven't programmed in Rust, but I can't find the video on your channel, did you upload it?
@silakanveli6 ай бұрын
Please just keep going with C. This content is fantastic a When it is minimalistic.
@kamertonaudiophileplayer8476 ай бұрын
@@nirlichtman I didn't do a video yet, just created a similar program.