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
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); ```
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
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)
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 😊
@@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
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 😂
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
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?
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"
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.
@@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?
@@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.
@@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.
@@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.
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
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);
```
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
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*).
Very clear and concise purpose und workflow! I look forward to the next videos👋🙌
What kind if books do you recommend us to have a solid understanding of C if we are beginner for C?
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)
@@nirlichtman win32/64 is death, but doesn't know it yet.
For absolute beginners K&R is also good one.
Nicely done!
suggestion : make a terminal text editor like nano or vim
Have a look at Nir Lichtman's "Minimalist Text Editor" put up about 2 weeks ago.
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 😊
What terminal do you use?
looks like the windows terminal xD
Unironically I think this is Windows with a DWM port for the layout
@@greybrunix What is a DWN port?
@@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
@@nirlichtmanOk I thought it looked like Windows Terminal lol
Even if you’re writing code just for fun and not for production you should do it right.
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".
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 😂
pretty much every things is based on C/C++, java, perl, etc.
I have always wondered why argv is a pointer of a pointer, why, just why does that "magically" turn into an array of strings?
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
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?
@@Zeutomehr so an array is a pointer to a location of the memory with sequential data?
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"
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...
In (buffer, 1, 1024, f), the "1" would be the size of what exactly?
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.
@@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?
@@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.
@@nirlichtmanoh, I get it now, thank you
@@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.
How can you can call a file VIEWER an Editor?
Since it is also an editor, it has an edit command ('e') that can modify the bytes
also what if the file has more than 1024 characters?
it will only deal with the first 1024 of the file and ignore the rest
@@ahmedsat4780 oh ok thanks
@@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.
@@xblxckxpxny1005That is correct, part of why the code is just for fun and not for production :)
@@xblxckxpxny1005
i know 😊😊 but I might not be able to express it correctly because English is not my first language
thanks for correcting me.
bro uses windows terminal on linux
he uses wsl, windows sumsystem for linux
and yes, there are tiling wms for windows
He's using a windows port of dwm
@@myrix_dev sound cool ig, I knew of the dwm port but lately its been everywhere idk
Better than a bot 😋
still waiting for minimalist https server 😅
he already did that
no he didnt, he did an https CLIENT and an HTTP server.@@ZsomborBerki
I duplicated the video in Rust. Is anyone interested in?
That could be interesting, I haven't programmed in Rust, but I can't find the video on your channel, did you upload it?
Please just keep going with C. This content is fantastic a
When it is minimalistic.
@@nirlichtman I didn't do a video yet, just created a similar program.