You are here

Web browser project in C, C program to open a website/url

C program to open a website entered by a user. It will launch Mozilla Firefox web browser to open a website so it should be installed on your computer, if you are using an another web browser then you can change path in the program.

C programming code

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <graphics.h>
  5. #include <dos.h>
  6. #include <string.h>
  7.  
  8. void initialize_graphics_mode();
  9. int get_key();
  10. void draw();
  11.  
  12. union REGS i, o;
  13.  
  14. main()
  15. {
  16.   int key, i = 0, xpos, ypos, button;
  17.   char arr[200], temp[5], *ptr;
  18.   char a[] = "C:\\Progra~1\\Mozill~1\\firefox ";
  19.  
  20.   strcpy(arr,a);
  21.  
  22.   i = strlen(a);
  23.  
  24.   initialize_graphics_mode();
  25.  
  26.   draw();
  27.  
  28.   while(1)
  29.   {
  30.     if(kbhit())
  31.       key = get_key();
  32.  
  33.     if((key>=97&&key<=122)||(key>=65&&key<=90)||key==46||key==47||key==63)
  34.     {
  35.       arr[i] = key;
  36.       sprintf(temp,"%c",arr[i]);
  37.       outtext(temp);
  38.       if(getx()>470)
  39.       {
  40.         clearviewport();
  41.         moveto(5,2);
  42.       }
  43.       i++;
  44.     }
  45.     else if (key == 13)
  46.     {
  47.       arr[i] = '\0';
  48.       system(arr);
  49.       break;
  50.     }
  51.     else if (key == 27)
  52.     {
  53.       closegraph();
  54.       exit(EXIT_SUCCESS);
  55.     }
  56.     if(button==1&&xpos>=150&&xpos<=480&&ypos>=300&&ypos<=330)
  57.     {
  58.       system("C:\\Progra~1\\Mozill~1\\firefox programmingsimplified.com");
  59.       break;
  60.     }
  61.     key = -1;
  62.   }
  63.  
  64.   closegraph();
  65.   return 0;
  66. }
  67.  
  68. void initialize_graphics_mode()
  69. {
  70.   int gd = DETECT, gm, errorcode;
  71.  
  72.   initgraph(&gd,&gm,"C:\\TC\\BGI");
  73.   errorcode = graphresult();
  74.  
  75.   if( errorcode != grOk )
  76.   {
  77.     printf("Graphics error : %s\n",grapherrormsg(errorcode));
  78.  
  79.     printf("Press any key to exit...\n");
  80.     getch();
  81.     exit(EXIT_FAILURE);
  82.   }
  83. }
  84.  
  85. int get_key()
  86. {
  87.   i.h.ah = 0;
  88.   int86(22, &i, &o);
  89.  
  90.   return( o.h.al );
  91. }
  92.  
  93. void draw()
  94. {
  95.   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  96.   outtextxy(275,11,"Web Browser");
  97.   outtextxy(155,451,"<a href="http://www.programmingsimplified.com"">www.programmingsimplified.com"</a>);
  98.   outtextxy(5,105,"Enter URL : ");
  99.   rectangle(120,100,600,130);
  100.   setviewport(121,101,599,129,1);
  101.   moveto(5,1);
  102. }