Anonymous
1030002 %10 Result is 2 /10 You're left with 103000
Anonymous
Until number > 0 is true loop assert number % 10 < 2 if it is true number = number / 10 next End if End loop If number <= 0 is true print true else print false
Serenity
Serenity
My program works well but as I quit the console this message is shown.
Serenity
char* convert_binary_to_string(int num) { char* bits; bits = (char*)malloc(sizeof(MAX_SIZE + 1)); if (bits == NULL) return NULL; int i = 0; for (i; i < MAX_SIZE; i++) { if ((num & LAST_BIT_MASK) == 0) bits[i] = '0'; else bits[i] = '1'; num = num << 1; } bits[MAX_SIZE] = '\0'; puts(bits); }
Serenity
Does it what causes the problem ?
Anonymous
It's just that you don't know the length of the number passed
Anonymous
BTW it's usually 10
Anonymous
So malloc(11)
Serenity
Thanks, your advice solved the issue.
Serenity
I've to learn more about dynamic memory allocation
Anonymous
sizeof(MAX_SIZE + 1) is probably equals to 4
Anonymous
But it's always the same number
Anonymous
What is malloc?
Serenity
char* bin_num=NULL; bin_num = convert_binary_to_string(num); while ('0' == *bin_num) { bin_num++; }
Serenity
bin_num is a string of binary numbers
Serenity
I want to clear out all of the zeros
Serenity
but it enters the loop just one time and then stops.
Anonymous
While '0'!=*bin_num
Serenity
that's what I want
Anonymous
What is bin num?
Serenity
bin_num is a string of binary numbers
Serenity
00000001011 for example , I just want to clear all the zeros.
Anonymous
That is not thw way u, ll miss out some zeros
Serenity
So I advance the pointer by one each time until I meet the MSB
Anonymous
It should be like this For(int i=0;i<bin. Length();i++) If(bin[i]=='0') bin. erase(bin. Begin()+i);
Anonymous
This works too i guess
aisyah
Hii, do you guys know any free version of matlab? I want to download it for my coursework
Serenity
Serenity
What does this warning mean ?
Anonymous
What does this warning mean ?
It means that it's wrong to do this: int* get_x() { int x = 0; return &x; }
Nils
Hi, what does that mean? It looks somewhat weird
Nils
But it compiles
Spirit
Doesn't look like it
Spirit
Looks like error not warning
Nils
the compiler doesn't show that error, only the IDE does
Nils
What's the code
#include <ostream>
Nils
When I remove that it's fixed
Spirit
Wierd
Vishal
http://www.vishalchovatiya.com/variadic-template-cpp-implementing-unsophisticated-tuple/
Dima
well, it has no ad and has a nice design. nevermind:)
(╯°□°)╯
Hello everybody
Nils
std::vector<std::string> command = strsplit(message, ':', 1); std::vector<std::string> tempsplit = strsplit(command[1], ' ', 1); command[1] = tempsplit[0]; command.push_back(tempsplit[1]); Why does the second case cause a logic error if the delimiter wasn't found but the first one doesn't?
Nils
strsplit(): std::vector<std::string> strsplit(std::string_view s, char delimiter, std::vector<std::string>::size_type times = 0) { std::vector<std::string> to_return; decltype(s.size()) start = 0, finish = 0; while ((finish = s.find_first_of(delimiter, start)) != std::string_view::npos) { to_return.emplace_back(s.substr(start, finish - start)); start = finish + 1; if (to_return.size() == times) { break; } } to_return.emplace_back(s.substr(start)); return to_return; }
Anonymous
Anonymous
False positive response of static code analyser
klimi
signal rocks
Anonymous
👍
Anonymous
Hello, Can anyone explain why doesnt this works and why does that.. char *lol(){ char *str = "ooooo"; return str; } int main(){ printf("%s", lol); } this results in garbage. But when i catch its return in main as follows: char *m = lol(); printf("%s", m); it works. how and why
Anonymous
Why is the function a pointer?
it returns a pointer to char... isn't it so?
Prometheus
I’m just trying to figure out the purpose of doing it all that way. Also, when the function lol ends wouldn’t str be destroyed? Might be why it doesn’t work.
Prometheus
I hate pointers so I don’t know for sure but I think you just return a pointer to a now non existent variable’s memory location.
Anonymous
I’m just trying to figure out the purpose of doing it all that way. Also, when the function lol ends wouldn’t str be destroyed? Might be why it doesn’t work.
Well the purpose of the code is nothing but to understand the underlying concepts. Yes exactly, it will be destroyed. Both ways its being destroyed. But one way works when we store the pointer as char *m = lol(); but other way doesn't. Im trying to understand why
Prometheus
u didn't call the function in 1st case as i can see at first
He’s right as well. You’re printf doesn’t have parentheses at the end of lol
Prometheus
I feel like an idiot. I was looking for the most complicated reason it wouldn’t work well instead of the actual text
I_Interface
lol so silly
it happens
Anonymous
it happens
thank you so much Sergey 🎈
I_Interface
Prometheus
me too hahahhaah
Give his fix a try and let us know if it works. I’m curious if the pointer thing I brought up will be an issue
I_Interface
thank you so much Sergey 🎈
The best practice is using debugger. With it u can watch executing of your code step by step.
Anonymous
Btw where does the concept of local variable go ? i mean variables are discarded once we leave the function. Right ? So whats happening ? should i assume these are string literals and they're constant? or what
I_Interface
I prefer the printf(“Got to like 21”); method lol
Works too, but if u can use debugger as a normal programmer, why u should do that ?)
Prometheus
Works too, but if u can use debugger as a normal programmer, why u should do that ?)
It was more of a joke. I’ve never used a debugger before, honestly.