!SGkzNqBXEJutSYnahE:matrix.org

C

88 Members
C Programming Ask C related questions here.12 Servers

Load older messages


SenderMessageTime
21 Oct 2020
@chexier1:matrix.orgcaionov *

EpicFailGuy hello world:

:::c
#include <stdio.h>

int main(void)
{
	char *hello = "Hello, world!";
	fwrite(hello, sizeof(char), 420, stdout);
	hello[0] = 's';
	return 0;
}
14:04:44
@chexier1:matrix.orgcaionov *

EpicFailGuy hello world:

:::c#include <stdio.h>

int main(void)
{
	char *hello = "Hello, world!";
	fwrite(hello, sizeof(char), 420, stdout);
	hello[0] = 's';
	return 0;
}
14:04:50
@chexier1:matrix.orgcaionov *

EpicFailGuy hello world:

#include <stdio.h>

int main(void)
{
	char *hello = "Hello, world!";
	fwrite(hello, sizeof(char), 420, stdout);
	hello[0] = 's';
	return 0;
}
14:04:56
@chexier1:matrix.orgcaionov

fixed:

#include <stdio.h>
#include <string.h>

int main(void)
{
	char *hello = "Hello, world!";
	char buf[1337];
	strcpy(buf, hello);
	fwrite(buf, sizeof(char), sizeof(buf), stdout);
	hello[0] = 'c';
	return 0;
}
14:16:20
@chexier1:matrix.orgcaionov *

fixed:

#include <stdio.h>
#include <string.h>

int main(void)
{
	char *hello = "Hello, world!";
	char buf[1337];
	strcpy(buf, hello);
	fwrite(buf, sizeof(char), sizeof(buf), stdout);
	hello[0] = 'c';
	return 0;
}
14:18:57
@solar:privacytools.ioSolarstrcpy is insecure caionov, use strncpy instead15:07:41
@kosshi:matrix.orgkosshiwhats the point of that actually, why fwrite? it doesnt terminate on a null so you get garbage15:20:07
@kosshi:matrix.orgkosshi * whats the point of that actually, why fwrite? it doesnt terminate on a null so you get garbage15:21:37
@chexier1:matrix.orgcaionovexactly15:21:58
@kosshi:matrix.orgkosshiah, a joke hello world?15:23:13
@chexier1:matrix.orgcaionovyes, this may be the worst way possible to print a string15:25:25
@chexier1:matrix.orgcaionov~~I actually got this idea from a pro-Rust meme~~15:27:37
@chexier1:matrix.orgcaionov * ~~I actually got this idea from a pro-Rust meme~~15:27:43
@kosshi:matrix.orgkosshi
#include <stdio.h>

int main(void)
{
	printf( "%li\n", (long int)(int[1]){} );
	return 0;
}
15:29:16
@kosshi:matrix.orgkosshi *
#include <stdio.h>

int main(void)
{
	printf( "%li\n", (long int)(int[1]){} );
	return 0;
}```

here's the worlds worst random number generator
15:29:19
@kosshi:matrix.orgkosshi *
#include <stdio.h>

int main(void)
{
	printf( "%li\n", (long int)(int[1]){} );
	return 0;
}```
15:29:23
@kosshi:matrix.orgkosshiworlds worst random number generator15:29:38
@kosshi:matrix.orgkosshi *
#include <stdio.h>

int main(void)
{
	printf( "%li\n", (long int)(int[1]){} );
	return 0;
}
15:29:43
@chexier1:matrix.orgcaionov

short version:

fwrite("Hello, world!", sizeof(char), 4 * 1024, stdout);
*(int *)0 = 0;

(write hello world + garbage and dereference a null pointer)

16:23:54
@chexier1:matrix.orgcaionov *

short version:

fwrite("Hello, world!", sizeof(char), 4 * 1024, stdout);
*(int *)0 = 0;

(write hello world + garbage and dereference a null pointer)

16:24:07
@chexier1:matrix.orgcaionov For some reason nothing is written to the screen if size is too low... 16:25:23
@kosshi:matrix.orgkosshi youre lacking a \n i guess 16:28:26
@kosshi:matrix.orgkosshi at least my terminal likes to forget outputting anything unless \n is sent 16:29:06
@neui:matrix.orgNeui caionov: It is most likely because of buffering from the c library; You want to use fflush(stdout); to make sure it writes it. 17:43:42
@neui:matrix.orgNeui kosshi: There is the posix function setvbuf where you can set different types of buffering, one of them is line-buffered, which is likely the default when it is connected to a terminal 17:44:49
22 Oct 2020
@chexier1:matrix.orgcaionovThanks for the tip.02:17:08
@chexier1:matrix.orgcaionovI've been literally dreaming in C recently... Am I ascending?02:17:47
@grill12513:matrix.orggrill12513>Serial Experiments Lain ( 1998)02:18:35
@chexier1:matrix.orgcaionov I've finally implemented wc... gotta git gud. 04:16:03
23 Oct 2020
@grill12513:matrix.orggrill12513 changed their profile picture.07:02:34

There are no newer messages yet.


Back to Room List