#include <stdio.h>
#include <string.h>
#include <ctype.h>
int Prev_Room, quest_end;
char choice1;
int inputtest(char test1[], char test2[]);
void quest();
void room2();
int inputtest(char test1[], char test2[]) {
size_t test1lenght = strlen(test1);
int check1 = 0, check2 = 0;
for (int i = 0; i < test1lenght; i++)
{
if ((test2[0] == test1[i]) && (test2[1] == test1[i+1])) {
check1 = 1;
}
}
return (check1 == 1)? 1:0;
}
void room1() {
int leave_room1;
leave_room1 = 0;
while (leave_room1 != 1) {
printf("Your are in room 1\n[1]: Quest\n[2]: Room 2\n");
gets(choice1);
if (inputtest(choice1, "qu") == 1) {
system("cls");
quest();
}
else if (inputtest(choice1, "ro") == 1) {
system("cls");
room2();
}
}
}
void quest() {
printf("Type 1 to end quest\n");
scanf("%d", &quest_end);
if (quest_end == 1)
{
system("cls");
room1();
}
}
void room2() {
int leave_room2;
leave_room2 = 0;
choice1 = 0;
while (leave_room2 != 1) {
printf("Your are in room 2\n[1]: Room 1\n");
scanf("%d", &choice1);
switch (choice1)
{
case 1:
system("cls");
room1();
}
}
}
int main() {
system("cls");
room1();
return 0;
}
#Code keeps crashing exe (again)
122 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
choice1 is a char, which can only store a single letter. A string is an array of chars
Also, gets is unsafe and deprecated. use fgets instead
What’s the difference between gets and fgets
fgets takes the length of the buffer it's reading into, so it can stop and avoid a buffer overflow
char* fgets(char* str, int count, FILE* stream);
// ... and 1 more
Defined in
<stdio.h>
What’s a buffer overflow
What’s a buffer
Excerpt from the fgets manpage:
Bugs
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
A buffer is just some memory, like e.g. char my_buffer[100]; <-- this would be a 100 byte buffer
char str[5]; // only has 5 spaces
for (int i = 0; i < 10; i++) {
str[i] = 'a'; // this will keep going past the last space and write into whatever memory is after the array
}
100 bytes???? Not bits???
C only counts sizes in bytes, we don't have direct interaction with bits (outside of bitwise integer operations)
Ah I see, that sounds like it would fuck up a code
We have 100 chars.
1 char is 1 byte.
(or bitfields)
Damn… arrays will kill my memory won’t they
no, haha
why would they
Smth like
char buf[1'000'000];
```would be 1 megabyte (1 MB)
1 infinte loop combined with an array and its GGs
char buf[1'000'000'000]; would be 1 GB (although that'd be too large for your stack)
No?
Arrays aren't created at runtime
that only matters if you end up computing a bad index to access the array with
Whats a stack
Oh right mb
char arr[2];
while (1) {
arr[0] = 'a'; // infinite loop but no issues
}
Yeah I see why I sounded dumb
I see, how big is the stack? And do I ever have to worry about the issue of it being too full?
no issues besides your CPU core responsible for that program "idling" at 100% usage
depends on the system, but usually a couple megabytes on modern desktop computers
If you want more memory then you'll need to use the heap where you can get memory from using malloc
!man malloc
malloc, free, calloc, realloc, reallocarray - allocate and free dynamic memory
Synopsis
#include <stdlib.h>
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
void *reallocarray(void *ptr, size_t nmemb, size_t size);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
... (truncated)
Big advantage of malloc is not only that you have practically unlimited memory but also that you can allocate that memory at runtime e.g. from a user input
Unlimited sounds like it wouldn’t end well for me ngl
Disadvantage is that you need to manually free it and that it's a bit slower than the stack
heap isn't slower than stack
heap allocations are slower than stack allocations
access is same
Well, it's not really unlimited. Can only go up to how much RAM you have (+ a bit more due to operating system magic)
Yeah, I didn't want to dive too deep for now
But yeah, the whole OS part around it is what makes it slow
Man, okay time to get a degree in CS ig, screw engineering
engineering is cooler
id say memory management is more computer engineering than CS
CS is mainly algorithms, graph and set theory, linear algebra and stuff
probability
Okay then, time to switch majors, screw mechatronics
"Computer science" is kind of a bad wording, its more "Computing science"
mechatronics is dope tho
(It is, but we just don’t get deep enough into anything)
well you cant really fill your memory with general data if you arent working with huge arrays
Insert childish "that's what she said" joke
Do u think there are online clubs I can join
like i made a small 2d game in C for last semesters homework assignment(2k lines of code, not too much), it uses like 30 MBs of memory with all textures and text loaded into memory after they are used once
My uni don’t got engineering clubs, mostly community
YO WAI- THERES A GUI IN C?
not built-in
I used a library :)
Which one?
Is it hard to use?
I’m currently attempting to make a game for my final project in C
start one. the club I joined was started when some students were digging around in the engineering building's basement, found some cool stuff, and decided to make stuff with it
Oh I don’t have enough knowledge in anything in engineering to start a whole as club, I can barely write some code and I suck ass at mechanics
there's only one way to learn
those students didn't know squat about the things they found
found a professor who did to advise them, learned the rest as they went
knowledge gets passed down each year, and while I was there we ended up setting a couple world records
I’m planning to go to a course this summer that dives deep into all engineering aspects, they told me that at the end of the course I’ll have to submit a project that’s on the level of an engineering graduation project
Would that’s badass
not really.
https://github.com/nevemlaci/Prog1_NHF1 this is the whole project
i think you can just
git clone https://github.com/nevemlaci/Prog1_NHF1.git
and open it up with visual studio code and run it with the play button at the top right(i have a visual studio code task attached for running/debugging)
the code is horrible tho
but basically sdl allows you to create a window, renderer and load+render textures and stuff
very basic media library
I see, ill do that when i get the internet to downlaod things 👍
You only got the upload version of the internet rn?
(Internet is going at 2b/s on my laptop rn)
Huh? How can you even send and receive Discord texts
easily, I'm working on a 22b/s connection right now
Isn't that like ~60-100 characters per second?
So if I send an incredibly long paragraph of say 2k characters that all require 4 bytes UTF-8, then it'd take you more than a minute to receive the whole text, no?
why?
more speed = more power
I mean you could almost carry the data by hand to Discord and it'd be faster
In computer networking, IP over Avian Carriers (IPoAC) is a joke proposal to carry Internet Protocol (IP) traffic by birds such as homing pigeons. IP over Avian Carriers was initially described in RFC 1149 issued by the Internet Engineering Task Force, written by David Waitzman, and released on April 1, 1990. It is one of several April Fools' ...
Is there also such a joke article for "IP over Aryan Carriers"?
@glad inlet Such a shame that you don't know German, because there's an entirely different Wikipedia dedicated to joke articles, like e.g. the "W-Lan-cable" or the "W-Lan-pipe".
E.g. for the "W-Lan-cable" they even give the materials it's build from:
78.1%Nitrogen20.9%oxygen0.93%Argon0.03%carbon dioxide0.01%hydrogen10.98%plutonium2.718%Dilithium1.93%oxdrahdium0.002%anionic and non-ionic surfactants0.001%pro-retinol-α nanosomes (prevent wrinkling)
It’s made of… earths atmosphere?
I really don't think that the earth's atmosphere is 10.98% plutonium
If this is a serious question then think about it again.
What does the W in W-Lan stnad for?
Yeah, up to the hydrogen it's the earth's atmosphere, starting from the plutonium we're actually surpassing the 100% barrier
the dilithium is important so we can maintain a warp field tho
true
wouldn't want to imagine what it'd be like without warping.
Imagine travelling by moving like a peasant
I prefer gate travel personally
not yet…
Silly, of course it is