Angelo
strcmp returns 0 for equal strings, yes? then if (strcmp(str1, str2)) {...} else {...} should go to the else block if str1 and str2 are equal.
exactly but isn't it more logically if that worked for the if block? the condition is true so don't execute the else?
Pavel
exactly but isn't it more logically if that worked for the if block? the condition is true so don't execute the else?
Not sure what you mean. You can think of it as adding != 0 to the end. so if (i) the same as if (i != 0). And in C++ at least it usually highly recommended to use the second form (if it's not a bool operator call that is intended) as it's more clear.
Angelo
so the condition is true when it's not equal to 0, instead for a function like strcmp it's true when it's equal to 0
Angelo
don't know, I find it a bit confusing
Angelo
Thank you Pavel
Pavel
it true when it's not zero, and false if it is zero
Angelo
it true when it's not zero, and false if it is zero
if the strings matches (true) it will return 0
Pavel
if the strings matches (true) it will return 0
why true? strcmp doesn't return true or false, it returns int
Pavel
0 if equal, not zero if not equal
Angelo
alright so I associated that zero meant true
Angelo
that's why I was confused I think
Foxner
https://www.programiz.com/c-programming/library-function/string.h/strcmp
Pavel
yep, it's better not think of strcmp's contract as of are strings equal, better something like compare strings and return relationship
Angelo
Angelo
I needed this clarification I think 😂
Angelo
alright writing it like this it's better I think
Foxner
strcmp returns a value that represents the difference between the first characters encountered that are different in the two strings (0 if there is no difference). It has nothing to do with the logic 0 or false.
Foxner
If a function returns an integer rather than a boolean there's usually a reason for it.
Pavel
alright writing it like this it's better I think
I agree, I'm not a C programmer, but for me this == 0 is a clear sign that you check for strings equality
Foxner
No, it is not required to return difference. Implementation which returns only -1, 0 or 1 is perfectly valid
Interesting, I didn't know that. But there are still three values, and you can't represent three different values with a boolean.
Artöm
Of course
Foxner
It does make some sense though. I assume the non-zero values are mostly used for sorting purposes anyway.
Ash
Wtf
Ash
Brother this group is for coding enthusiast not for religious opinionz
Anonymous
Hello brothers
Ash
Hi
Roxifλsz 🇱🇹
Fuck
Roxifλsz 🇱🇹
That was wrong msg
Ash
Hehe yeah
Anonymous
Guys I'm running into trouble, I'm a beginner c++ programmer and I was studying sockets (Linux implementation) and I my program have this struct: c++ typedef struct data_header { uint8_t dh_fmt; uint16_t dh_len; }__attribute__((packed)) DataHeader; The goal is to transform this in a uint8_t array, (inside a function and then return it, by reference or return statement), and obviously vice-versa since I need to convert it back when it reaches the client.
Anonymous
Plz help me guys xD I already digged so many stack overflow threads without result that I even thinking in forfeit c++
Ash
👆
What's with this?
Noble Friend
What's with this?
It's what you see🤔
Anonymous
👆
Ugh, ty but this wouldn't solve the problem 😔
Ash
It's what you see🤔
I meant do u want the output or ur running into some errors?
Anonymous
Errors while printing, the data became inconsistent with my current approach
Ash
I need to download it on a system... Its difficult to interpret it on the mobile
Noble Friend
Ash
Go read it I explained all please.
Can u please tag the message where u explained... I wanna try it..
Ash
Errors while printing, the data became inconsistent with my current approach
Sorry neeko I don't know about the linux implementation... I am also a beginner in C
Noble Friend
Ash
Yes
Shall I make a new program for u? Or should i debugg yours?
Noble Friend
Um. This question?🤔
Anonymous
c++ uint8_t raw[3]; raw[0] = dh.dh_fmt; //dh is a DataHeader& param raw[1] = (dh.dh_len & 0xFF00) << 8; raw[2] = (dh.dh_len & 0x00FF); raw_data = raw; // raw_data is a *&uint8_t param
Anonymous
Lol
Dima
Anonymous
Ok didn't want to format xD
Noble Friend
👆
Mine runs well but it isn't exactly what was ask.
Noble Friend
Okay i am trying to run it. ..
Just remember it's a c program not cpp. Thanks
Ash
Just remember it's a c program not cpp. Thanks
Yeah buddy i can see that lol.. 😅
Noble Friend
😊
Ash
😊
Well now I can see the problem and i am working on it..
Ash
Hopefully i will be able to provide u with a solution
Noble Friend
If you can, then thank you
Ash
If you can, then thank you
Btw.... What place value system u want to use? Like millions, billions?
Noble Friend
It has to work for all. Just as the question says. There's no more specifications than those of the question
Ash
Okay got it..
Noble Friend
Burhan
#freeprogrammingbooks
Anonymous
Char n[10]; Printf("enter name") ; Scanf("℅S", n) ; Printf("%s", n) ; n have address of n[] so scanf will take input as usual but why printf is taking address and printing name though?
Artöm
/report suspicious
Anonymous
Hi As we know log(x) has value only at x>0. Is there any way to set log(x) at -infinity < x < infinity in c++?
Anonymous
Because I want to plot the range value of log(x) for example from -10 to +10
Joesph
Log0 = 1
Joesph
x = 0