Pages

Monday, October 10, 2016

C program to print text at given position on screen.



C program to print text at given position on screen.

#include <windows.h>
#include<stdio.h>
#include<conio.h>
COORD c = {0, 0};

void setxy (int x, int y)
{
 c.X = x; c.Y = y; // Set X and Y coordinates
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

int main()
{
 int x, y, rollno;
 char name[10];

 printf("Enter your Roll No.:");
 scanf("%d", &rollno);

 printf("Enter your name:");
 scanf("%s", name);

 printf("Where you want to print on Screen?\n");
 printf("Enter your X coordinate:");
 scanf("%d", &x);

 printf("Enter your Y coordinate:");
 scanf("%d", &y);

 setxy(x,y);
 printf("Your Roll No. is %d.", rollno);

 setxy(x,y+1); //add 1 in y to print at new line
 printf("Your Name is %s.", name);

 return 0;
}



Output of the program:

Enter your Roll No.:101
Enter your name:Purva
Where you want to print on Screen?
Enter your X coordinate:10
Enter your Y coordinate:10





          Your Roll No. is 0.
          Your Name is Purva.



2 comments:

  1. Replies

    1. Dear viewer, it's working fine with my Windows system. Please share your exact error and your system configuration to locate your error. You can share your code and errors through contact form given at the bottom of this page.

      Delete