ברני
But because I wrote it inside the case it called it again in the loop no?
olli
So I need to start with in ask Question before the all thing?
if you have code such as the following it will fail. Once you're in main it tries to find out what foo is, but your compiler has no idea because you have not defined or declared it before. int main() { foo(); } void foo() {}
olli
void foo(): // declare foo, // compiler knows `foo` is a function returning void int main() { foo(); // compiler has seen `foo` before // now you can use it } // define foo void foo() { }
olli
But because I wrote it inside the case it called it again in the loop no?
no, you want a loop, that repeats itself until a condition is no longer met, e.g. this goes on and on until you enter 0 using a loop #include <stdio.h> int main() { char c; while (true) { scanf(" %c", &c); if (c == '0') { break; } printf ("%c is not 0\n", c); } return 0; } while you might can achieve similar using recursion, it's not recommended and might blow up your stuck
olli
Yea but my task is to do it with switch.. Or do you mean I can do it inside also?
was just meant to be an example, the principle of using loops does not change
olli
in your case, this goes on until you enter 4 int askQuestion() { int question; question = 0; while (question != 4) { printf("Welcome ..."); scanf(" %d", &question); switch (question) { // ... todo } } }
Anonymous
Hello guys
Anonymous
Iam santhosh
Anonymous
Iam eager to learn the program and thanks to all in advance
Anonymous
Hello, guys anyone to assist o. This
Wisenky
How can I delete a whole line inside a csv file using c++ ?
Wisenky
Couldnt find a good solution
Merazi
Nomid Íkorni-Sciurus
Dima
/warn
Do you want one?
D
Do you want one?
Всмысле ?
Pavel
Всмысле ?
1. Don't abuse bot commands 2. English only
Anonymous
Hi, someone in acm.timus?
Ayush
Hi
Ayush
I am getting segmentation fault in some test cases on hackerrank. I have tried all the things but still the issue persists. Can anyone help me regarding this?
Ayush
Dynamically allocating using malloc
Anonymous
Use address sanitizers on your computer
Ayush
Didn't got it. Could you please elaborate more
Anunay
/warn
You sure?
Anunay
Use address sanitizers on your computer
As a preventive measure against corona? 😂
Anunay
Jk
Rizni
Hi to all I want to store binary values like Int num,binary; cin>>num; binary = bitset<32>(num); cout << binary; [Error] cannot convert 'std::bitset<32ull>' to 'int' in assignment Please help me
Rizni
what do you want to do?
I'm trying to get binary values for user input hex value and then store it to a variable Then using functions I can convert it to other base values easily
Emir
#include <iostream> class A {}; void foo(A&(&&)) { std::puts("foo called\n"); } int main() { A ax; foo(ax); } Can someone explain that code? How called func(A&(&&)) with func(A ax) parameter
Asuna 🍓
#include <iostream> class A {}; void foo(A&(&&)) { std::puts("foo called\n"); } int main() { A ax; foo(ax); } Can someone explain that code? How called func(A&(&&)) with func(A ax) parameter
<source>:5:15: error: cannot declare reference to 'class A&', which is not a typedef or a template type argument 5 | void foo(A&(&&)) | ^
Wisenky
<source>:5:15: error: cannot declare reference to 'class A&', which is not a typedef or a template type argument 5 | void foo(A&(&&)) | ^
or main.cpp:5:15: error: cannot declare reference to ‘class A&’, which is not a typedef or a template type argument void foo(A&(&&)) ^ lol
Emir
Asuna 🍓
idk 👀
Ayush
Hey.. i am still looking for the solution. Please let me know if anyone can help
olli
Hey.. i am still looking for the solution. Please let me know if anyone can help
It's impossible to answer your question. If you would have asked a good question I'm pretty sure somebody would have answered it by now
Ayush
The question is to insert a node at given index in linkedlist. I am solving it on hackerrank using C
Ayush
struct node_t *new_node=(struct node_t *)malloc(sizeof(struct node_t)); struct node_t *current_node=list->head; new_node->data=item; int i=0; while(i!=index-1) { current_node=current_node->next; i++; // printf("Reached here\n"); } new_node->next=current_node->next; current_node->next=new_node;
Ayush
Here is the code
Ayush
Getting segmentation error in 2 cases out of 5
Ayush
I mean so there would be no solution for that test case.
olli
I don't know all the details to the question, maybe you should add it at the back or return null to indicate the error. Dereferencing null and crashing your program is not a good idea tho
Ayush
Can you please suggest how can I check this condition?
Ayush
I have simply traverse the list while current_node is not null and then I have break when the index is equal to i
olli
That could be a solution
Ayush
So if the value of index is higher than the loop won't break and it couldn't return segfault
Ayush
But it also doesn't solved the issue
olli
Which issue? Not dereferencing null will prevent a seg fault
Ayush
Segfault .. still getting segfault after implementing
olli
Well then I guess check your code again and make sure all the pointers are valid
Ayush
Already checked. I am not able to figure out the cause of this issue
Ayush
I have modified it like While(current_node not NULL) if i==index-1 break
professor
Anyone have ever worked in sync codes?
Merazi
Hey guys, I hope you're all having a great day I need to ask you a question: If I have a pointer, Can I create another pointer that points to the previous pointer? For example, I have this snippet of code: int temp = *(ptr+j); // *(ptr+j) = arr[j] *(ptr+j) = *(ptr+j+1); // *(ptr+j+1) = arr[j+1] *(ptr+j+1) = temp; I need to convert temp into a pointer
Merazi
but it is getting an integer from another pointer that is pointing to an array of integers
Merazi
yes
Vlad
Anonymous
hey I have a math problem
Anonymous
I know the derivative of tanh(x) = sech^2(x) but if I want to derivative of a value that's already been through tanh(x) then it 1 - tanh^(x); How does one compute what the derivative will be the value has been through the original function ? Like how do I get to; 1 - tanh^(x);