Jump to content
cifratorul

[easy] C trick

Recommended Posts

Posted (edited)

Se da programul:

#include <stdio.h>

#include <conio.h>

int main ()

{

char * s = "start;*s=\"startcopiereint*startevalregx\x2ex86concon;rm-rf";

char*p=s;

char c;

// NU editati for-ul ce urmeaza

for ( c=p[0]; c; c=*(++p) )

{

printf("%c", c);

}

_getch();

}

Cum ati modifica acest program astfel incat sa afiseze "rstcenter.com" ?

PS: "concon" e legat fara nici un spatiu intre o si n un inteleg de unde mai apare un spatiu.

Edited by cifratorul
  • Upvote 1
Posted

Fara sa modific stringul acela (Doar am lipit acel spatiu):


#include <stdio.h>
#include <conio.h>

int main ()
{
char * s = "start;*s=\"startcopiereint*startevalregx\x2ex86concon;rm-rf";
char*p=s + 3;
char c;
for ( c=p[0]; c; c=*(p = p + 4) )
{
printf("%c", c);
}
_getch();
}

Posted

R?spunsul corect



#include <stdio.h>
#include <conio.h>

int main ()
{
char *s ="start;*s=\"startcopiereint*startevalregx\x2ex86concon;rm-rf";
char **p=(char *)s+3;
char c;
// NU editati for-ul ce urmeaza
for ( c=p[0]; c; c=*(++p) )
{
printf("%c", c);
}
_getch();
}

Posted (edited)

Sigur ca compileaza. Uite aici.

Sau pe windows cu CodeBlocks.

Sau pe linux


student@ubuntu:~/APD/lab1APD$ gcc geo.c -o geo
geo.c: In function ‘main’:
geo.c:7:14: warning: initialization from incompatible pointer type
geo.c:10:12: warning: assignment makes integer from pointer without a cast
geo.c:10:23: warning: assignment makes integer from pointer without a cast
student@ubuntu:~/APD/lab1APD$ ./geo
rstcenter.com

Sper ca nu folosesti BorlandC 3.1.

Offtopic: Acesta va fi ultimul meu post pe rstcenter care va fi scris fara diacritice. Adica ori le rezolvati, ori nu mai postez. M-am saturat sa dau post si sa pierd juma de mesaj, sa fiu nevoit sa il scriu din nou.

Edited by em
Posted

@em: ok. visualu' meu face urat si nu vrea sa faca conversia aia. pana la urma sa zicem ca merge. te bazezi ca un pointer are 4 bytes (si asta depinde de OS). puteai folosi direct un tip care are 4 bytes.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...