Vlad
You can't return pointer to VLA array
Vlad
It is destroyed after the end of scope
Michel
How can I check If one of the argv equals some predefined char string?
G
how to use line in parameter while ((getline(&line, &len_host, fhost)) != -1) { curl_easy_setopt(curl, CURLOPT_URL, line);
G
the parameter receives char*
Anonymous
how to use line in parameter while ((getline(&line, &len_host, fhost)) != -1) { curl_easy_setopt(curl, CURLOPT_URL, line);
Use line.data() You must use C++17 or above because before C++17, data returned a const char*.
Αλι
How can I check If one of the argv equals some predefined char string?
first copy it to some buffer to be safe. then use strcmp. if 0 they match.
Michel
first copy it to some buffer to be safe. then use strcmp. if 0 they match.
Ah! I was using that but I assumed strcmp would return a bool, and used that 0 as not matching 😅
Anonymous
'''int main(int argc, char *argv[]) { // input calculador do tit cout << "Que valor tens?"; int escolha; int tit = 0; int tilp = 0; int tip = 0; do{ cout << "Que valores tens?\n 1.Tit\n 2.Tilp \n 3. Tip \n 4. Calcular valor em falta\n"; cin >> escolha; switch(escolha){ case 1: cin >> tit; break; case 2: cin >> tilp; break; case 3: cin >> tip; break; case 4: tit = tilp + tip; cout << "Tit :" << tit << endl << "Tip:" << tip << endl << "Tilt:" << tilp << endl; case 5: cout << "Programa encerrado" << endl; break; } } while(escolha != 5); }''' Why is this not working I wanna give 2 inputs at any given time and then press 4 to print all the values but it never hits right
Anonymous
Hi. Are linkedin courses worth it?
Please check the message above. Those are the only recommendations we are making. If you need info on anything outside of that, you will have to do your own research. And in future, please stick to asking questions only related to C and C++ in this group
Anonymous
Suppose if size of integer is of 4 bytes in our computer then using short in front of integer makes it of 2 bytes but on the other hand using long as modifiers in front of integer allows integer data type to take more memory space. Can anyone please explain how it will take more memory when system itself is size of integer as only 4 bytes ?
Anonymous
and one more why error is shown in my system when I use %d format specifiers to the sizeof operator but the error will get resolved if I use %ld
Sonny
Hi guys random question about class constructors. If I have a class and I don't set up any specific constructors, do I still need to declare them? Class::Class()=default; or is it okay to just leave them out all together? what's the best practice?
Sonny
thanks
Igor
Hello, guys! Has anyone worked with https://github.com/tesseract-ocr/tesseract. I am wondering how to setup a config to properly recognize text on image. Right now, ocr recognize only one piece of text, but not all. Can't send media file unfortunately
Teatro
hello. how can i asiggn a word in another line? this don't work main () { char a[5]; a="asdd"; cout <<"end"<<a; }
\Device\NUL
In linux lp64 while windows llp64. The only way to make it portable is using (u)intX_t from stdint
Teatro
strcpy(a, "asddd") a is array of char
Ohh so many thanks, I forgot that 😱 Btw with string type I can use a="adds"
\Device\NUL
Ohh so many thanks, I forgot that 😱 Btw with string type I can use a="adds"
std::string is different with char * Althought you can convert it to const char * with .c_str() method
\Device\NUL
You shouldn't mix C++ stuff with C stuff
Teatro
Get it👍
Nawras
I have a program that when i enter a string like character (a) i get it in ascii number and i get the length of it so i want to put the ascii number by the length , for example number 3 the length is 4 so it printf(“s”,result) the output will be (3333)
Nawras
How can i make this work i found the length and the asci number but can put it in array and put it into the (result)
Nawras
Lets say you have string and length
Nawras
You want to make array that it multiple the string for length times
Nawras
And make this another string to print it
Nawras
Can i send you the question translated
\Device\NUL
Can i send you the question translated
The maximum string output is 4 char, so when the string length is more than 4 char, it only outputs 4 char
\Device\NUL
printf("%.3s", "abcde") The output is only abc because the max field width is 3 char
Pumpkin
#include <stdio.h> int main() { int a; printf("this is %d\n", a); } Hello, Why this variable 'a' defaults to 0 here?
Anonymous
compiler usage to maintain int =0
Vlad
Reading uninitialized variables is undefined behavior
Vlad
It does only for debug builds
And only for gcc and clang
Vlad
MSVC would fill it up with 0xcccccccc memory pattern
Achille
hi everyone , I hope you're doing well ! I would like to send email in my Qt c++ app , someone have a suggestion for me ?
Ольга
Good day. Sorry to bother you but I do not understand why in this program when entering the title of a book consisting of two words is remembered only the first. I will be glad for any help https://onlinegdb.com/qn-mJL0v4
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Good day. Sorry to bother you but I do not understand why in this program when entering the title of a book consisting of two words is remembered only the first. I will be glad for any help https://onlinegdb.com/qn-mJL0v4
Perhaps I'm mistaken, but when you assign the struct to a variable, shouldnt you use malloc? Like, when I'm practicing with lists and I have a struct typenode, I do: typeNode *variable= malloc(sizeof(typeNode)); Don't know if this will solve, just an idea, because the rest of the code seems right to me
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
please tell me if I'm wrong, so I won't make the same mistake again
Fenimoure
Evening! Need some help with my C++ program: I have to create a two directional list using structures. A part of a task is to create a push_back(int) function which will push an integer to the end of a list. In addition, in the twodirlist structure we store only the adress of the front of the list, so we have to use a self-developed function get_back() which returns us a node of the last element (a structre that contains data of an element, adresses of the previous and the next element). Problem is, while creating the list itself and getting the last node, I struggle storing the adress of the previous node. Could you, please, tell me where I make the mistake? biNode *twoDirList::get_back() { biNode* temp = front; biNode* temp_prev = nullptr; biNode* back = temp; while(temp){ temp = temp->next; if (temp) back = temp; if(back) back->prev = temp_prev; temp_prev = temp; } return back; } biNode *twoDirList::push_back(int x) { if (!front){ front = new biNode(x); } else { get_back()->next = new biNode(x); } return nullptr; }
Ольга
Good evening. I can't understand what's wrong again, at what point something goes wrong. I will be grateful for any help https://onlinegdb.com/CV4ybR4Yq
Fenimoure
Your get_back logic is convoluted and wrong. You can just do this: binode* temp = front; while(temp && (temp = temp->next)); return temp; And typically in a bidirectional list, you store a pointer to both the head and the tail of the list.
Your solution won't store the adress of the previous node, as far as I understand, it will just go to the end of the list and return the last node, but I also have to store the adress of the previous nodes in the nodes processed 🤔 P.S. Not storing the back node is a part of a task
Csc's Saitama
Good day
מנחם
while(num--) I know when a number reaches zero, the condition is false. But what happens if the number is negative? For me it keeps running. -1 are true?
מנחם
Everything non 0 is true
so what return -1?
Vlad
so what return -1?
-1 is evaluated to true
מנחם
-1 is evaluated to true
what different return 1 // return -1?
\Device\NUL
\Device\NUL
Non Zero value will treated as true
Vlad
what different return 1 // return -1?
If you return bool from a function there is no difference
Vlad
However why won't you just return true?
Anonymous
Your solution won't store the adress of the previous node, as far as I understand, it will just go to the end of the list and return the last node, but I also have to store the adress of the previous nodes in the nodes processed 🤔 P.S. Not storing the back node is a part of a task
Why do you need to do that? You are saying it is a bidirectional list. That means you maintain 2 pointers in each node : one to the previous node and one to the next node. You can iterate through the list in any direction. And the solution I gave for getting the back node doesn't require storing any previous nodes which is how it should be (if you dont store a pointer to the tail)
️Skill
is this code correct? Book::~Book() { delete[] this->_name; delete[] this->publisher._name; delete[] this->publisher._version; } Book::Book(const Book &copy) { size_t len = wcslen(copy.name()); _name = new wchar_t[len+1]; wcscpy_s(_name, sizeof(wchar_t) * len, copy._name); because i'm keep getting Exception 0xc0000005 encountered at address 0x7ffd90aa609b: Access violation reading location 0xffffffffffffffff at deleting _name