Posted: . At: 8:28 AM. This was 2 years ago. Post ID: 16337
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Another way to code a very simple C program. Print text to the terminal.


There is yet another way to print useful code to the terminal in C.

This program below shows a very simple way to print text to the terminal and this is not using printf().

simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <sys/uio.h>
 
int main(void) {
 
	struct iovec buffers[4];
	buffers[0].iov_base = "party";
	buffers[0].iov_len = 5;
	buffers[1].iov_base = " ";
	buffers[1].iov_len = 1;
	buffers[2].iov_base = "on";
	buffers[2].iov_len = 2;
	buffers[3].iov_base = " dude.\n";
	buffers[3].iov_len = 5;
 
	writev(1, buffers, 4);
	return 0;
}

I found this code here: https://flylib.com/books/en/1.381.1.84/1/.

But this is a very useful way to make a super simple Hello World program.

simple2.c
1
2
3
4
5
6
7
8
9
10
11
#include <sys/uio.h>
 
int main(void) {
 
	struct iovec buffers[1];
	buffers[0].iov_base = "Hello World.";
	buffers[0].iov_len = 12;
 
	writev(1, buffers, 1);
	return 0;
}

The above is another very simple C program. This prints Hello World and is as simple as it can get.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.