Marcio
I did it for free, as a lecturer
Shubh Joshi
Hello coders How can I store around 10^6 characters in a single string? Google is suggesting malloc or linked list Bt I don't know properly Can you please suggest any other way?
Shubh Joshi
Just do the push function and instead of pushing numbers...., push characters, easy
Sorry I couldn't understand Can you pls explain something more Or please provide any source related to this
Alviro Iskandar
Hello coders How can I store around 10^6 characters in a single string? Google is suggesting malloc or linked list Bt I don't know properly Can you please suggest any other way?
the size of 1000000 characters doesn't even reach 1MB, so single array of chars should be enough local variable on the stack should be still capable to handle it, by default stack size is limited at 8MB but, yeah, for this size you better use heap from malloc(). No need to invent a linked list for this anyway
Alviro Iskandar
char *p = malloc(1000001); if (!p) { // handle ENOMEM } // you can fill p here call free(p) after you no longer use it
Anonymous
Sorry I couldn't understand Can you pls explain something more Or please provide any source related to this
struct Node {   char data;   struct Node *next; }; void push(struct Node** head_ref, char new_data) {     struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));     new_node->data  = new_data;     new_node->next = (*head_ref);     (*head_ref)    = new_node; }
Shubh Joshi
Ohk got it Thanks👍
Anonymous
Np
<|>
hi, i need parser code in c language. can anyone help?
Nils
Hey, is this the right way to execute the function at addr in char* execmem: void (*fun_ptr)() = execmem; fun_ptr(); ?
\Device\NUL
Well then , cast it into void . Am I right ?
\Device\NUL
But that&#39;s function, not data
\Device\NUL
type func(void) { return something; } int main(void) { (void)func(); } Like this
<|>
parse the code inside the file
Botirjon
guys, who can help me? i need best compiler for c++ on macbook, not visual studio, any other free app
Anshul
this is the question https://leetcode.com/problems/increasing-order-search-tree/ and this is how i have attempted it but idk why i am getting an error, someone please look at the code
Anshul
https://pastebin.com/29MrQpZf
Peace
I have an array of length n with integer values. I calculated maximum integer(mx) of that array. I declared and defined a vector of pairs. Vector is of length max and pair consist bool, int. vector&lt;pair&lt;bool,int&gt;&gt; v(mx,make_pair(false,0)); Now, when I am looping through the array upto array length n and printing values stored in vector as follows, for(int i=0;i&lt;n;++i){ cout &lt;&lt;v.at(a[i]).first &lt;&lt; &quot; &quot; &lt;&lt; v.at(a[i]).second &lt;&lt; endl; } it is showing me this error terminate called after throwing an instance of &#39;std::out_of_range&#39; what(): vector::_M_range_check: __n (which is 4) &gt;= this-&gt;size() (which is 4) how the vector could be out of range if i am using element of array as indices of vector ?
Anshul
because your vector indices will range in between [0,max-1] so when you do v.at[a[i]] a[i] can be max too, and in that case your index will be out of range
Peace
Try using iterators, or show code
thanku , but anshul helped me for the answer already.
ㅤㅤㅤ
If we have to insert value in vector STL we use push_back. But what is we have to take input from user ??
ㅤㅤㅤ
Anshul
Take input the value obviously
mohammed
hey guys,some help here pls.i want to i want to sort this list alphabetically and want songs with the title “Untitled” to always appear at the top
mohammed
ذ vector&lt;string&gt; temp (1); for(int i=1; i&lt;vect.size(); i++) { for(int j=1; j&lt;vect.size(); j++) { if(vect[j-1]==&quot;Untitled&quot;) { ???????? } else if(vect[j-1] &gt; vect[j]) { temp[0]= vect[j-1]; vect[j-1]=vect[j]; vect[j]=temp[0]; } } }
mohammed
klimi
what function? O.o
mohammed
temp[0]=vect[j-1]; vect[j-1]=vect[0]; vect[0]=temp[0];
mohammed
what function? O.o
There is a problem with this line that if there are more than one untitled it sort only one
klimi
why not sort all of it and then move it?
klimi
or you could do it the opposite way, move untitled to the top and then sort the rest
mohammed
for(int i=1; i&lt;vect.size(); i++) { for(int j=1; j&lt;vect.size(); j++) { if(vect[j-1]==&quot;Untitled&quot;) { temp[0]=vect[j-1]; vect[j-1]=vect[0]; vect[0]=temp[0]; } else if(vect[j-1] &gt; vect[j]) { temp[0]= vect[j-1]; vect[j-1]=vect[j]; vect[j]=temp[0]; } } }
klimi
i don&#39;t think this is correct since you are hardcoding 0
klimi
vect[0]=temp[0]; &lt;- hardcoded 0
mohammed
vect[0]=temp[0]; &lt;- hardcoded 0
what to modify with it ?
Pavel
what to modify with it ?
vect[0] is the first element of vect, always
Pavel
You iterate over i, but never use i
mohammed
oh,
mohammed
thanx will try it
mohammed
vect[0] is the first element of vect, always
shouldn&#39;t i assign vect[0] to vect[j-1] which has value untitled???
Pavel
shouldn&#39;t i assign vect[0] to vect[j-1] which has value untitled???
What if you have two untitled? You will be just swapping them. What if it&#39;s not untitled?
J
Is it free
clang, gcc and to an extent, MSVC(that comes with VS) are free. (clang and gcc are also open source)
Pavel
shouldn&#39;t i assign vect[0] to vect[j-1] which has value untitled???
You can just make normal sorting function and then add a special case for untitled in the same way you did with the comparator above
Pavel
And your normal sorting function is incorrect now, because you sort only the first element basically
mohammed
if(vect[j-1]==&quot;Untitled&quot;) { temp[1]=vect[j-1]; vect[j-1]=vect[0]; vect[0]=temp[1]; }
Pavel
If there any thing you could tell me I well be thankful
So first of all, you want to sort the items and want untitled items to be first? If yes, first you need to fix your sorting algoritm. Just forget about untitled, you can remove that part for now. I guess you tried to implement a bubble sort? https://www.geeksforgeeks.org/bubble-sort/ You can compare the code with the implementation or try to execute your loops in your head step-by-step to figure out what is broken in your sorting algoritm. But I would suggest to use a debugger for that (just google &quot;how to use debugger in [name of your IDE]&quot;), it allows to execute your app step-by-step and investigate the state. Once you make your sorting work, test it on different inputs. Once you checked that it works on different inputs, instead of &quot;vect[j - 1] &gt; vect[j]&quot; you need to add a similar check with what we discussed the last time above with &quot;untitled&quot;. If you have a proper sorting algoritm you need to modify only the condition to achieve the correct behavior.
Anonymous
How many time would take to me be a competitive programmer
Anonymous
?
SR27
int a=1,b=2,c=3,d; d = ++a || ++b &amp;&amp; ++c; cout&lt;&lt;a&lt;&lt;&quot; &quot;&lt;&lt;b&lt;&lt;&quot; &quot;&lt;&lt;c&lt;&lt;&quot; &quot;&lt;&lt;d;
SR27
value of abcd?
SR27
just tell me value of abcd?
Anonymous
just tell me value of abcd?
the result depend on the different compiler
Iris
“undefined behavior”
SR27
“undefined behavior”
why can you explain
SR27
?
Peace
can anyone tell me the difference between bot and an algorithm ??
Dima
lol bruh
Iris
I just wanted to post a link from StackFlow🥲 sry
Iris
why can you explain
to answer this question