Byte-ul Posted March 14, 2017 Report Posted March 14, 2017 (edited) Inlocuiti "...." mai jos pentru a afisa "Muie Dragnea" in urma rularii. int main() { if (....) printf("Muie "); else printf("Dragnea"); return 0; } Fara printf, cout, puts, etc Au rezolvat: @RAZOR1g, @Philip.J.Fry, @Hertz, @kznamst, @Nytro, @adyshake Fara stackoverflow bai bulangiilor Raspunsurile pe PM. Edited March 14, 2017 by Byte-ul 7 Quote
adyshake Posted March 14, 2017 Report Posted March 14, 2017 Doar in if(...) avem voie sa modificam ? Quote
Hertz Posted March 14, 2017 Report Posted March 14, 2017 Just now, adyshake said: Doar in if(...) avem voie sa modificam ? Da Quote
tjt Posted March 15, 2017 Report Posted March 15, 2017 De ce solutiile numai pe privat? Cred ca ar fi mai misto sa fie facute publice, astfel poate am invata unele chestii noi. Quote
yoyois Posted March 16, 2017 Report Posted March 16, 2017 (edited) Pune solutiile pt curiosi. EDIT: Eu l-am rezolvat cred. Astept confirmarea. Edited March 16, 2017 by yoyois Quote
gigiRoman Posted March 16, 2017 Report Posted March 16, 2017 http://lmgtfy.com/?q=if+else+execute+both 1 Quote
Nytro Posted March 16, 2017 Report Posted March 16, 2017 int main() { if (ChuckNorris()) printf("Muie "); else printf("Dragnea"); return 0; } Era banal... 1 Quote
BogdanNBV Posted March 16, 2017 Report Posted March 16, 2017 (edited) 34 minutes ago, Nytro said: int main() { if (ChuckNorris()) printf("Muie "); else printf("Dragnea"); return 0; } Era banal... Nu cred ca toti stiu de "hrusca.h" "Hrusca stie cat dureaza vesnica pomenire" Edited March 16, 2017 by BogdanNBV Quote
Active Members MrGrj Posted March 16, 2017 Active Members Report Posted March 16, 2017 Cel mai usor era: int main() { if (fork()) printf("Muie "); else printf("Dragnea"); } Nu mai e nevoie de return 0; ca nu mai suntem in 2008. 1 Quote
Byte-ul Posted March 16, 2017 Author Report Posted March 16, 2017 22 minutes ago, MrGrj said: Cel mai usor era: int main() { if (fork()) printf("Muie "); else printf("Dragnea"); } Nu mai e nevoie de return 0; ca nu mai suntem in 2008. Bai garaj lasă c-ul ca ești paralel cu el Ramai la Python. Quote
Active Members MrGrj Posted March 16, 2017 Active Members Report Posted March 16, 2017 2 minutes ago, Byte-ul said: Bai garaj lasă c-ul ca ești paralel cu el Ramai la Python. How come ? Quote
Philip.J.Fry Posted March 16, 2017 Report Posted March 16, 2017 (edited) 1 hour ago, MrGrj said: Nu mai e nevoie de return 0; ca nu mai suntem in 2008. Am citit si eu ceva asemanator intr-o carte de C++, a fost nasoala cartea.. 1 hour ago, MrGrj said: How come ? #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(void) { pid_t child_pid; char *tasks[] = {"Task1", "Task2", "Task3", "Task4", "Task5"}; const int task_no = 5; for (int i = 0; i < task_no; ++i) { child_pid = fork(); if (child_pid == 0) { // Child printf("Child: I got to do %s\n", tasks[i]); _exit(i); } else { // Parrent printf("Parrent: Spawned child %d\n", i); } } printf("\nI'm going to wait for my children now.\n"); printf("Hopefully they don't turn into zombies\n\n"); int status = -1; for (int i = 0; i < task_no; ++i) { wait(&status); if (WIFEXITED(status)) { printf("Parrent: My child is not a zombie, yay.\n"); printf("Parrent: Child %d finished, yay!\n", WEXITSTATUS(status)); } } return 0; } Edited March 16, 2017 by Philip.J.Fry 1 Quote
Active Members MrGrj Posted March 16, 2017 Active Members Report Posted March 16, 2017 3 minutes ago, Philip.J.Fry said: Am citit si eu ceva asemanator intr-o carte de C++, a fost nasoala cartea.. #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(void) { pid_t child_pid; char *tasks[] = {"Task1", "Task2", "Task3", "Task4", "Task5"}; const int task_no = 5; for (int i = 0; i < task_no; ++i) { child_pid = fork(); if (child_pid == 0) { // Child printf("Child: I got to do %s\n", tasks[i]); _exit(i); } else { // Parrent printf("Parrent: Spawned child %d\n", i); } } printf("\nI'm going to wait for my children now.\n"); printf("Hopefully they don't turn into zombies\n\n"); int status = -1; for (int i = 0; i < task_no; ++i) { wait(&status); if (WIFEXITED(status)) { printf("Parrent: My child is not a zombie, yay.\n"); printf("Parrent: Child %d finished, yay!\n", WEXITSTATUS(status)); } } return 0; } Nu inteleg ce vrei sa demonstrezi cu postul de mai sus Quote
Philip.J.Fry Posted March 16, 2017 Report Posted March 16, 2017 1 minute ago, MrGrj said: Nu inteleg ce vrei sa demonstrezi cu postul de mai sus Quote
Byte-ul Posted March 17, 2017 Author Report Posted March 17, 2017 (edited) 23 hours ago, MrGrj said: How come ? Am uitat sa-ti raspund. Compileaza aia si iti dai seama singur. tl;dr unele standarde C au nevoie de return in main sau rezulta undefined behavior. Edited March 17, 2017 by Byte-ul Quote
gigiRoman Posted March 22, 2017 Report Posted March 22, 2017 Zygote performs a fork, creating a new process that is a clone of itself, drops privileges and sets its UID appropriately for the application’s sandbox, and finishes initialization of Dalvik in that process so that the Java runtime is fully executing. For example, it must start threads like the garbage collector after it forks. Quote
Okjokes Posted March 25, 2017 Report Posted March 25, 2017 On 3/23/2017 at 7:39 PM, AndRewu said: Am descoperit 2 metode :))) Da? Care-s alea? Quote
tjt Posted March 25, 2017 Report Posted March 25, 2017 On 3/22/2017 at 0:19 PM, gigiRoman said: Zygote performs a fork, creating a new process that is a clone of itself, drops privileges and sets its UID appropriately for the application’s sandbox, and finishes initialization of Dalvik in that process so that the Java runtime is fully executing. For example, it must start threads like the garbage collector after it forks. Ce treaba are Androidul cu challenge-ul asta ? Quote
AndRewu Posted March 25, 2017 Report Posted March 25, 2017 5 hours ago, Okjokes said: Da? Care-s alea? prima pui in if prima conditie negata , si a2a , egalezi prima conditie cu ce vrei tu if(!printf("Mue ")) if(printf("Mue ")==oricenumar) Quote
a13x4nd7u Posted March 25, 2017 Report Posted March 25, 2017 (edited) 6 hours ago, tjt said: Ce treaba are Androidul cu challenge-ul asta ? Cred ca e offtopic ce a scris el, dar merge compilat si pe Android, ca doar e linux (try "termux" and you get console). 6 hours ago, Okjokes said: Da? Care-s alea? Exista cel putin 2 metode (fork() - deja precizat de MrGrj sau vfork()) Am o curiozitate ce ma macina. Ar putea merge vreodata ceva ce seamana cu ceea ce e scris mai jos? (Incerc sa rescriu "jmp" care apare in locul "else"-ului, in functia "main". Din cunostintele mele e o incercare nereusita, din cauza optimizarilor diferitelor compilatoare, dar.. ar putea merge ceva de genul macar pe un compilator, cu optiunile de compilare specificate? A treia conditie din "if" era o incercare de a pacali compilatorul ca pot folosi ambele ramuri, atat "if" cat si "else". Nu merge intotdeauna si uneori poate optimiza si sa dispara una din ramuri "if"/"else" la compilare. Pozitiile 39 si 40 nu sunt chiar random, sunt preluate cu un hexeditor (diferenta de la inceputul adresei functiei main pana la adresa "else" in asamblare, iar instructiunea "jmp" in cazul meu era pe 2 octeti asa ca am pus 2 NOP (0x90 pentru x86) ). Codul nu mi-a mers, am primit un "Segmentation fault (core dumped)". ) Spoiler int main() { if ( ((((char*)main)[39] = 0x90) == 0x90) && ((((char*)main)[40] = 0x90) == 0x90) && (((char*)main)[10] != 1) ) printf("Muie "); else // aici face "jmp" la adresa la care se face "return 0;"; am incercat sa rescriu acest "jmp" printf("Dragnea"); return 0; } Edited March 25, 2017 by a13x4nd7u Adaugare explicatii Quote
tjt Posted March 25, 2017 Report Posted March 25, 2017 (edited) 8 minutes ago, a13x4nd7u said: Cred ca e offtopic ce a scris el, dar merge compilat si pe Android, ca doar e linux (try "termux" and you get console). Exista cel putin 2 metode (fork() - deja precizat de MrGrj sau vfork()) Am o curiozitate ce ma macina. Ar putea merge vreodata ceva ce seamana cu ceea ce e scris mai jos? (Incerc sa rescriu "jmp" care apare in locul "else"-ului, in functia "main". Din cunostintele mele e o incercare nereusita, din cauza optimizarilor diferitelor compilatoare, dar.. ar putea merge ceva de genul macar pe un compilator, cu optiunile de compilare specificate? A treia conditie din "if" era o incercare de a pacali compilatorul ca pot folosi ambele ramuri, atat "if" cat si "else". Nu merge intotdeauna si uneori poate optimiza si sa dispara una din ramuri "if"/"else" la compilare. ) Hide contents int main() { if ( ((((char*)main)[39] = 0x90) == 0x90) && ((((char*)main)[40] = 0x90) == 0x90) && (((char*)main)[10] != 1) ) printf("Muie "); else printf("Dragnea"); return 0; } La asa ceva de genu' m-am gandit si eu, dar nu cred ca e posibil. Experienta mea e limitata in ASM, asa ca poate gresesc, dar cred ca in momentul in care ai facut jump nu poti sa mai faci return ci pleaca de la linia respectiva. Edited March 25, 2017 by tjt 1 Quote