What the hell is that code even meant to do?
da_cow (she/her)
She/her 🏳️⚧️
Professional cow, Linux Nerd, Hardcore Techno enthusiast. The Emporer protects us.
- 5 Posts
- 50 Comments
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
1·9 months agoYes, I did type it out manually (not really, I just copy pasted it and changed the according values)
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
6·9 months agoJust stupid
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
21·9 months agoIts already written in C1
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
6·9 months agoThis is 100% true. I never plan on actually using this. It might be useful for working on microcontrollers like an ESP32, but apart from that the trade of for more computational power is not worth the memory savings.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
6·9 months agoHmmmmmmm, that sounds like another fun idea. Trying to make storing a single char as inefficient as possible.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
3·9 months agoI do sometimes work with microcontrollers, but so far I have not encountered a condition where these minimal savings could ever be useful.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
8·9 months agoI know. This whole thing was never meant to be very useful, and more like a proof of concept
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
3·9 months agodid not want to always scroll past that behemoth of a switch case xD
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
2·9 months agoI am constantly on how I can allow Uppercase, without significantly reducing the posiible amounts of chars
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
5·9 months agoIdk, I just had this funny idea, and thought I could do this as a cool and quick proof of example
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
9·9 months agoAh, thats cool. Did not knew you could that… Thanks.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
35·9 months agoDid not knew that this existed, but yeah its kinda like that. Except that I only allow 5 characters.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•Yes, I did spend time on this
7·9 months agoDamn, that are setups where you have to get creative.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•I got to avoid memory management for quite some time
3·9 months agoI did not knew this existed, so thanks for the tip.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•I got to avoid memory management for quite some time
3·9 months agoYeah, but I kinda dont want to learn/use C++
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•I got to avoid memory management for quite some time
8·9 months agoI found the mistake. Since the country code char array only has a size of 2 it overwrites the \0 char causing the memory to leak.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•I got to avoid memory management for quite some time
10·9 months agoThanks, I did not knew this. I always appreciate constructive criticism. I am quite new to C so theres a shit ton of stuff I have never done or dont even know about.
da_cow (she/her)@feddit.orgOPto
Programmer Humor@programming.dev•I got to avoid memory management for quite some time
9·9 months agoThis is the code I used:
#include <stdio.h> #include <string.h> #define MAX_ACCOUNTS 255 typedef struct { unsigned int id; char account_creation_date [10]; char first_name [255]; char last_name [255]; char country_code [2]; unsigned int iban; char password [255]; double balance; } account; account accounts_db[MAX_ACCOUNTS]; unsigned int accounts_created = 0; account get_account_id (unsigned int id) { int i = 0; while(i < MAX_ACCOUNTS) { if(accounts_db[i].id == id) { return accounts_db[i]; } i++; } account account; account.id = -1; return account; } void create_account(char first_name [255], char last_name [255], char password [255], char country_code [2]) { account new_account; new_account.id = accounts_created; strcpy(new_account.first_name, first_name); strcpy(new_account.last_name, last_name); strcpy(new_account.password, password); strcpy(new_account.country_code, country_code); strcpy(new_account.account_creation_date, ""); new_account.balance = 0.0; new_account.iban = 0; accounts_db[accounts_created] = new_account; accounts_created++; } int main() { char first_name [255] = "Max"; char last_name [255] = "Mustermann"; char country_code [2] = "DE"; char password [255]= "password"; create_account(first_name, last_name, password,country_code); account account = get_account_id(0); printf("Name: %s %s \n", account.first_name, account.last_name); printf("Account creation date: %s\n", account.account_creation_date); printf("IBAN: %s %d", account.country_code, account.iban); }``` When you run it you can see, that behind the country code of the IBAN you get the first two letters of the surename
Assuming this is real, how the fuck do you fuck up so badly?