!SGkzNqBXEJutSYnahE:matrix.org

C Programming Language

476 Members
C Programming Ask C related questions here.40 Servers

Load older messages


SenderMessageTime
4 Oct 2022
@ahto:artifact8.xyzahto
In reply to @trans_panda:matrix.org
I think I read about this problem. prime numbers are some difficult math stuff that only appears in college problems. IRL I think people just use pre-computed maps and whatnot. I could be wrong though
Difficult to compute quickly but not a difficulty concept
20:03:32
@trans_panda:matrix.orgtrans_panda 🏳️‍⚧️ (they/them)
int isprime(int a) {
	int i, j;	
	for (i = a - 1; i > 0; i--) {
		for (j = a - 1; j > 0; j--) {
			if ((j * i) == a)
				return 1;
		}
	}
	return 0;
}
20:04:41
@trans_panda:matrix.orgtrans_panda 🏳️‍⚧️ (they/them)somthing like this?20:04:45
@trans_panda:matrix.orgtrans_panda 🏳️‍⚧️ (they/them)I never went to computer school to see these problems irl20:04:59
@layap:matrix.org@layap:matrix.org joined the room.21:49:30
@layap:matrix.org@layap:matrix.org left the room.21:54:03
5 Oct 2022
@huayra1:matrix.orghuayra1 you should check to make sure a is a sane value. signed integer overflow is undefined 00:59:15
@huayra1:matrix.orghuayra1if the value was -((2^32)+1), it could overflow01:00:37
@huayra1:matrix.orghuayra1 a little pedantic, but you should also use int32_t, etc 01:01:12
@huayra1:matrix.orghuayra1i'm going to assume the compiler will do the rest of the optimizations regarding bit hacks and such01:05:09
@huayra1:matrix.orghuayra1* i'm going to assume the compiler will do the rest of the optimizations regarding bit hacks and such (for something this simple, there is much to do anyways)01:05:39
@huayra1:matrix.orghuayra1* i'm going to assume the compiler will do the rest of the optimizations regarding bit hacks and such (for something this simple, there is not much to do anyways)01:05:48
@hopingstar1806:matrix.orghopingstar1806 joined the room.02:30:48
@admin:beparanoid.dehnhx

what would be the best way to empty an array like this?

char foo[10240][256];

this is what i do rn:

memset(entry_list, 0, 10240);

is this good, or should i do something else?

10:01:04
@admin:beparanoid.dehnhx *

what would be the best way to empty an array like this?

char foo[10240][256];

this is what i do rn:

memset(foo, 0, 10240);

is this good, or should i do something else?

10:01:17
@twkmhnnomn:matrix.orgthose who know me have no need of my nameArrays are never empty. A loop is usually acceptable too.10:08:21
@n_r_k:matrix.orgNRK
In reply to@admin:beparanoid.de

what would be the best way to empty an array like this?

char foo[10240][256];

this is what i do rn:

memset(foo, 0, 10240);

is this good, or should i do something else?

memset takes size in bytes
11:50:04
@n_r_k:matrix.orgNRKit should've been `memset(foo, 0, sizeof foo);` instead11:50:30
@n_r_k:matrix.orgNRKbut if you're trying to *initialize* it, as opposed to resetting it, you can just initialize the first element to 0, the rest of the elements will be implicitly zero-ed.11:51:11
@n_r_k:matrix.orgNRK`char buf[256] = {0};`11:51:22
@admin:beparanoid.dehnhxah okay thanks11:55:09
@root6:matrix.orgroot6 * read an integer from user if it is prime number, print "true" if it isn't prime number, print "false"14:40:21
@matrix_help:matrix.org@matrix_help:matrix.org left the room.19:48:05
@admin:beparanoid.dehnhx

why isnt copy() a syscall when rename() is? (https://man7.org/linux/man-pages/man2/syscalls.2.html)

I mean with rename() you can move files with the file content to another path, why doesn't copy() exist then as a syscall?

I find this p weird.

20:31:36
@name_missing:matrix.orgname_missingI guess atomic and stuff.20:33:06
@name_missing:matrix.orgname_missingCopy is more complex.20:33:15
@admin:beparanoid.dehnhx how, rename() has a copy in it since it can move files with its content to another path 20:33:51
@admin:beparanoid.dehnhxhttps://man7.org/linux/man-pages/man2/rename.2.html20:34:28
6 Oct 2022
@kim_martial:matrix.org@kim_martial:matrix.org joined the room.13:35:07
@kim_martial:matrix.org@kim_martial:matrix.org left the room.15:56:29

There are no newer messages yet.


Back to Room List