Current Events > Ugh dealing with "strings" in C is such a pain.

Topic List
Page List: 1
DevsBro
10/25/18 12:48:11 AM
#1:


I like how sometimes it will work except somehow it screwed up something like 30 lines later.

How do you even.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
Rob Cesternino
10/25/18 12:50:18 AM
#2:


I love working with strings in JavaScript. You just put them in double quotes, and you're done.
---
Stop asking me if I'm Jessica Simpson. Jewish girls
Survivor is the greatest show EVER. are hawt
... Copied to Clipboard!
DevsBro
10/25/18 12:51:51 AM
#3:


Lots of languages have decent string handling.

Actually, C is the only one I've used that is anywhere near as dumb with them as it is.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
DevsBro
10/25/18 12:54:40 AM
#4:


Ah I see. I forgot to null terminate it after the strncpy.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
DevsBro
10/25/18 1:01:01 AM
#5:


Booyah!

Now my game can automatically check on startup to see whether the user has chosen a particular language, and if not, ask the Operating System what its default language is, pick the closest fit if there is no explicit equivalent language (IE if I don't support Australian English it can default to US English), lazy load dialog from encrypted dialog files, and throw it into a text box, menu, etc.

Pretty good step forward today. :)
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
YukihoHagiwara
10/25/18 1:06:21 AM
#6:


it's .com
---
7Dd_jr_dF0Y
... Copied to Clipboard!
Tyranthraxus
10/25/18 1:07:23 AM
#7:


C doesn't really have strings the way other languages do. They are char arrays. And yes they all need to be null terminated. I think some compilers will do it for you but C generally assumes you know what you're doing and will let you make a non null terminated string of you really want to.
---
It says right here in Matthew 16:4 "Jesus doth not need a giant Mecha."
https://imgur.com/dQgC4kv
... Copied to Clipboard!
Shadowplay
10/25/18 1:19:17 AM
#8:


Thought that this would be about guitars tuned down to C Standard.
---
I make a topic in Final Fantasy 12 to ask if Tifa! They said no Tifa. Hardness gone!-gandob
... Copied to Clipboard!
DevsBro
10/25/18 8:03:13 AM
#9:


Tyranthraxus posted...
C doesn't really have strings the way other languages do. They are char arrays. And yes they all need to be null terminated. I think some compilers will do it for you but C generally assumes you know what you're doing and will let you make a non null terminated string of you really want to.

Yeah I just don't do a lot of C so I didn't think about it and malloc'd and copied the actual length instead of length + 1.

A char array that isn't null terminated is actually valid and sensible in lots of cases, considering it's also the one-byte integer type. Or maybe you really do want an array of characters. Maybe it's a fake word generator or something and you want to keep track of which letters are vowels, frigatives, liquids, etc.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
FairyLeviathan
10/25/18 8:05:41 AM
#10:


How much do you know about Python?
... Copied to Clipboard!
DevsBro
10/25/18 8:23:06 AM
#11:


Not much. I've been learning a little lately because RPi GPIO controls are built in it but I'm really not a fan so far.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
1337toothbrush
10/25/18 8:23:26 AM
#12:


It can be tedious, but I like the flexibility.
---
... Copied to Clipboard!
scar the 1
10/25/18 8:37:49 AM
#13:


Some questions:

Why are you using C? Because you want to, or are you forced to use it somehow?
Would you consider using a string library to make things more convenient? If so, https://stackoverflow.com/questions/4688041/good-c-string-library
---
Everything has an end, except for the sausage. It has two.
... Copied to Clipboard!
DevsBro
10/25/18 8:40:58 AM
#14:


1337toothbrush posted...
It can be tedious, but I like the flexibility.

C has fantastic conditional compilation features, is the main reason I have these few C source files.

The majority of my code for this is in Ada, which people like to crap on but once you get used to it, it's a great language for, well, preventing stuff like this topic. Like straight up if you define a

type Single_Digit is range 0..9

It won't let you assign 10 to it, which is pretty standard, but the nice thing is it also won't let you do this:

declare
X : Single_Digit := 6;
Y : Integer;
begin
Y := X;
end


Unless you either explicitly cast to an Integer or change the Single_Digit definition from a type to an Integer subtype.

It's great because it always makes sure you are sure you want to do what you're asking it to do and didn't just brainfart something.
---
53 LIII 0b110101
p16 0x35
... Copied to Clipboard!
pinky0926
10/25/18 8:55:37 AM
#15:


Strings in C is relatively easy because if you have a keyboard nearby you can just tune to that. It's a big bright sound too, hard to mistake a C on strings

wait
---
CE's Resident Scotsman.
https://imgur.com/ILz2ZbV
... Copied to Clipboard!
1337toothbrush
10/25/18 10:48:24 AM
#16:


DevsBro posted...
1337toothbrush posted...
It can be tedious, but I like the flexibility.

C has fantastic conditional compilation features, is the main reason I have these few C source files.

The majority of my code for this is in Ada, which people like to crap on but once you get used to it, it's a great language for, well, preventing stuff like this topic. Like straight up if you define a

type Single_Digit is range 0..9

It won't let you assign 10 to it, which is pretty standard, but the nice thing is it also won't let you do this:

declare
X : Single_Digit := 6;
Y : Integer;
begin
Y := X;
end


Unless you either explicitly cast to an Integer or change the Single_Digit definition from a type to an Integer subtype.

It's great because it always makes sure you are sure you want to do what you're asking it to do and didn't just brainfart something.

That's great. I like my type system being as strong and static as possible. Compile-time checks are the best and their utility is lost on these python/javascript-slinging chucklefucks who think "all the things" should be written in those hacky languages.
---
... Copied to Clipboard!
Rexdragon125
10/25/18 10:57:21 AM
#17:


1337toothbrush posted...
That's great. I like my type system being as strong and static as possible. Compile-time checks are the best and their utility is lost on these python/javascript-slinging chucklefucks who think "all the things" should be written in those hacky languages.

Yup, there's a good reason why Google transpiles to Javascript
... Copied to Clipboard!
scar the 1
10/25/18 11:56:05 AM
#18:


1337toothbrush posted...
these python/javascript-slinging chucklef***s who think "all the things" should be written in those hacky languages.

I love Python but the opinion that everything should be written in that language gives me an aneurysm
---
Everything has an end, except for the sausage. It has two.
... Copied to Clipboard!
Topic List
Page List: 1