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);
}
Anonymous
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
Anonymous
sizeof(MAX_SIZE + 1) is probably equals to 4
Anonymous
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
Anonymous
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
Anonymous
Serenity
Serenity
What does this warning mean ?
Nils
Hi, what does that mean? It looks somewhat weird
Spirit
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
Spirit
Nils
When I remove that it's fixed
Spirit
Wierd
Vishal
http://www.vishalchovatiya.com/variadic-template-cpp-implementing-unsophisticated-tuple/
Dima
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
Nils
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
Prometheus
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.
I_Interface
Anonymous
Prometheus
I feel like an idiot. I was looking for the most complicated reason it wouldn’t work well instead of the actual text
Anonymous
I_Interface
Anonymous
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
Anonymous
Prometheus
Prometheus
Prometheus