V01D
does not work brother
What did you do
V01D
IN C you can only use "" for strings and ' ' for one character
Ishikawa
I am trying to create template file for IDE. I am trying to call system commands but of course they are not working because " closes on second " which i am putting for bash command.
locked
@Barneysworld , It would solve your issue hopefully :)
Ishikawa
thank you brother. you're awesome.
ברני
@Barneysworld , It would solve your issue hopefully :)
Ty alot! But I'm still a begginer but really ty I'll try to use it
Razni
Is there anyone good with the schema diagrams
Razni
Can anyone help me with it
ברני
Do you guys thinks it's a mistake I'm learning alone at home? 😔
Razni
Photo from Raz NI Zam
locked
You are welcome, keep in mind that when you want to make an algorithm take a pencil and sketching it would be too much helpful to you.
locked
@Barneysworld
locked
Yeah
ברני
I see, I'll try, ty alot!
locked
Have a nice day
ברני
V01D
using std::happy::D
Ammar
as soon as my function returns, it segfaults. 🤔
Because your function does not have return address.
Ammar
Like a new program when it starts from _start routine usually.
Nils
makes sense
Ammar
It should close itself with syscall exit.
Nils
I'll just call exit()
V01D
It should close itself with syscall exit.
Or ret. It the same as mov rax, 60 mov rdi, 0 syscall
Ammar
Or ret. It the same as mov rax, 60 mov rdi, 0 syscall
You could have used 32 bit register and xor edi, edi.
Ammar
For smaller code.
V01D
Well gcc will use smaller registers by default so
Ammar
Or ret. It the same as mov rax, 60 mov rdi, 0 syscall
ret is not the same as syscall exit though.
Ammar
ret is actually pop + jmp.
Ammar
If your top stack is not a valid return address, it will get segfault.
V01D
ret is not the same as syscall exit though.
The book I am reading claims that to be the same as the exit syscall
V01D
__syscall(60, 0) 😉
That is C though
Nils
Yeah
Nils
Can I wait for the child to exit?
Ammar
The book I am reading claims that to be the same as the exit syscall
It is correct for libc which is defined in main() function.
Nils
My code runs so fast parent exits before child is done with printing hello world lol
Alex
Can I wait for the child to exit?
you must: use wait or waitpid
Ammar
The book is about x86_64 assembly
The coding itself is in Assembly. But they usually link it to libc, I read some of them do that.
V01D
Ah
Ammar
I'll just call exit()
One important thing that may be forgotten: In case your parent process or process which shares the same virtual memory address runs more tasks after clone'ed thread exits, you should munmap() the mmap'ed thread stack to avoid memory leaks.
Nils
how do I get currents thread stack base ptr?
Nils
and stack size or end ptr
Ammar
how do I get currents thread stack base ptr?
After the clone() returns to your thread, its RSP register points to the top of your thread stack, you can pass the RSP value to global variable and read/write it from parent. void *thread_rsp; // global variable void init_thread() { __asm__ volatile("mov %%rsp, %0" : "=m"(thread_rsp)); job_thread(); }
Ammar
and stack size or end ptr
You should be able to determine this after calling mmap.
Nils
You should be able to determine this after calling mmap.
Yeah… But I need the stack size of the main thread
Ayush
Hi guys, Hope you all are doing well. I have solved a question on balanced brackets using stack on hackerrank. I have applied the correct logic. My code is working fine on C++ but It doesn't pass some test cases when I run it on C. I have modified the code to run on C language. There is no syntax error or any other warning in C but still it is not working correctly.
Ayush
I have tried to get the reference from Google. But I haven't got the answer for my question. It would be great if anyone can help me in this. Let me know if I can share my code here. Thanks
Alex
you can. thank you
Ishikawa
Why line breaks are not apperaing between the elements? What have I done wrong ?
Ishikawa
Alex
Why line breaks are not apperaing between the elements? What have I done wrong ?
try to launch your code online, probably this is console issue
Ishikawa
why is that required?
Ishikawa
why is that required?
i meant to reply that other guy who just deleted his msg.
Alex
:) yes, this is the reason
Ayush
you can. thank you
Thanks. I am sharing my code please refer to it
Ishikawa
oh! blyat. I feel like a dumb now. so sorry bros, my bad
Ishikawa
and ty so much
Ayush
#include <bits/stdc++.h> using namespace std; // Complete the isBalanced function below. #define MAXSIZE 1000 struct stack_define{ int top; int stack_items[MAXSIZE]; }stacknew; void stack_init(){ stacknew.top=-1; } int push(int data) { if (stacknew.top==(MAXSIZE-1)) { printf("Stack is full"); return -1; } stacknew.top++; stacknew.stack_items[stacknew.top]=data; return 0; } int pop() { if (stacknew.top==-1) { printf("Stack is empty"); return -1; } int data=stacknew.stack_items[stacknew.top]; stacknew.top--; return data; } int isempty() { if (stacknew.top==-1) { return 1; } return 0; } string isBalanced(string s) { int index; stack_init(); for (index=0;index<s.size();index++) { if(s[index]=='(' || s[index]=='[' || s[index]=='{') { push(s[index]); // stacknew.top++; // stacknew.stack_items[stacknew.top]=s[index]; // printf("pushed %c\n",s[index]); } else if( stacknew.top!=-1 && ( (s[index]==')' && stacknew.stack_items[stacknew.top]=='(') || (s[index]=='}' && stacknew.stack_items[stacknew.top]=='{') || (s[index]==']' && stacknew.stack_items[stacknew.top]=='[')) ) { // printf("popped %c\n",stack[top]); // stack[top--]; pop(); } else return "NO"; } if (stacknew.top==-1) return "YES"; else return "NO"; } int main() { ofstream fout(getenv("OUTPUT_PATH")); int t; cin >> t; cin.ignore(numeric_limits<streamsize>::max(), '\n'); for (int t_itr = 0; t_itr < t; t_itr++) { string s; getline(cin, s); string result = isBalanced(s); fout << result << "\n"; } fout.close(); return 0; } Here is my code on C language for hackerrank
Alex
#include <bits/stdc++.h> using namespace std; // Complete the isBalanced function below. #define MAXSIZE 1000 struct stack_define{ int top; int stack_items[MAXSIZE]; }stacknew; void stack_init(){ stacknew.top=-1; } int push(int data) { if (stacknew.top==(MAXSIZE-1)) { printf("Stack is full"); return -1; } stacknew.top++; stacknew.stack_items[stacknew.top]=data; return 0; } int pop() { if (stacknew.top==-1) { printf("Stack is empty"); return -1; } int data=stacknew.stack_items[stacknew.top]; stacknew.top--; return data; } int isempty() { if (stacknew.top==-1) { return 1; } return 0; } string isBalanced(string s) { int index; stack_init(); for (index=0;index<s.size();index++) { if(s[index]=='(' || s[index]=='[' || s[index]=='{') { push(s[index]); // stacknew.top++; // stacknew.stack_items[stacknew.top]=s[index]; // printf("pushed %c\n",s[index]); } else if( stacknew.top!=-1 && ( (s[index]==')' && stacknew.stack_items[stacknew.top]=='(') || (s[index]=='}' && stacknew.stack_items[stacknew.top]=='{') || (s[index]==']' && stacknew.stack_items[stacknew.top]=='[')) ) { // printf("popped %c\n",stack[top]); // stack[top--]; pop(); } else return "NO"; } if (stacknew.top==-1) return "YES"; else return "NO"; } int main() { ofstream fout(getenv("OUTPUT_PATH")); int t; cin >> t; cin.ignore(numeric_limits<streamsize>::max(), '\n'); for (int t_itr = 0; t_itr < t; t_itr++) { string s; getline(cin, s); string result = isBalanced(s); fout << result << "\n"; } fout.close(); return 0; } Here is my code on C language for hackerrank
this is not valid C code
Ayush
this is not valid C code
This code is working fine on C++ but some test cases didn't passed on C.
Ayush
I mean I just paste the logic inside the isBalanced function of this code
Ayush
In the c code that hackerrank provides
Ishikawa
what is blyat in japanese?
believe if or not, we simply say "fuck(fakku)" most of the time.