+2

what will do this code?

#include <stdio.h> #include <stdlib.h> int main() { int y=10; printf("\033[%dD",y); } please someone explain it what should i search to learn codes like this?

4/3/2020 6:46:58 AM

Reza

12 Answers

New Answer

+2

It is escape codes for console. printf("\033[%dD",y); means move cursor left specified number (y) columns. http://man7.org/linux/man-pages/man4/console_codes.4.html

+4

Reza what you are expecting from your code? Do you want to print value of ' y '

+4

Reza I have never seen anything like that. From where you get this code 🤔

+3

Reza can you share the link, from where you found about this. Because I haven't any idea about these terms.

+2

i think that i find the answer it uses ANSI code

+2

at first i was serching to find how to build console games with cpp that i find ncurses library then i searched for learning ncurses library there was a site that for comparing same program that was writen by ncurses and another one without it and there i find this code.. unfortunly that site's language 's persian sorry because my bad english link: https://barnamenevis.org/showthread.php?424858-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%D9%85%D9%82%D8%AF%D9%85%D8%A7%D8%AA%DB%8C-ncurses-%D8%AF%D8%B1-%D9%84%DB%8C%D9%86%D9%88%DA%A9%D8%B3 some english sites's link: https://notes.burke.libbey.me/ansi-escape-codes/ https://solarianprogrammer.com/2019/04/08/c-programming-ansi-escape-codes-windows-macos-linux-terminals/

+1

I wanaa to know what is "033[℅dD"

+1

let me send full code it is a code that will behave like ncurses library #include <stdio.h> #include <stdlib.h> int lasti=0,lastj=0; void goback(int x,int y ) { printf("\033[%dA",x); printf("\033[%dD",y); } void gotoxy(int x,int y ) { extern int lasti, lastj; goback(lasti, lastj); int i; for(i=0;i<x;i++) printf("\n"); for(i=0;i<y;i++) printf(" "); lasti=x; lastj=y; } int main(int argc , char* argv[]) { printf( "\e[2J\e[H" ); usleep(100900); int i = 1; int j = 20; // gotoxy(0,0); // printf("A"); usleep(100900); int b = 200; while(b) { gotoxy(i,j-6); printf(" _"); usleep(100900); gotoxy(i,j); printf(" BEHNAM"); usleep(100900); j++; if(j==60) { gotoxy(i,j--); printf(" "); j++; i++; j = 20; gotoxy(i,j); printf(" BEHNAM"); j++; } b--; } printf("\n\n"); return 0; }

+1

Maybe \033 is the ESC character, to reset the terminal, but I'm not sure.

-1

selamun aleygummm ahahah

-1

-1