Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 29-08-2008, 10:09 AM   #1 (permalink)
Traceur
 
zegulas's Avatar
 
Join Date: Oct 2003
Location: Mumbai
Posts: 276
Default Graphics program in C


I am trying to make a program which will accept the names and cordinates of the points to be plotted and then plot the points, its a graphics program in C language but sometimes the name given are not displayed properly (sometimes shows NULL or weird characters).

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <string.h>

int main()
{
	/* request auto detection */

	int gdriver = DETECT, gmode, errorcode, *vrt_x,*vrt_y,i,v;
	char** vrt_name;

	clrscr();


	/* initialize graphics and local variables */

	initgraph(&gdriver, &gmode, "C:\\TC\\BGI");

	/* read result of initialization */

	errorcode = graphresult();
	if (errorcode != grOk)  	/* an error occurred */
   	{
      		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
	        exit(1); 		/* terminate with an error code */
	}

	/*~~~~~~~~~Let the Plotting Begin!!!~~~~~~~~~~*/

	/* Asking for Vertices */

	printf(" How many vertices are there? ");
  	scanf("%d",&v);

	vrt_x =(int*)calloc(v,sizeof(int)); /* Initialized after accepting Vertices to determine */
	vrt_y =(int*)calloc(v,sizeof(int)); /* the size of memory to be alocated */
	vrt_name =(char**)calloc(v,sizeof(char));


	if(vrt_x!=NULL && vrt_y!=NULL && vrt_name!=NULL)
  	{
		for(i=0; i<v ; i++)
		{
			printf("\n Enter a name for vertice number %d ",i);
			scanf("%s",vrt_name[i]);
		}

		for(i=0; i<v ; i++)
    		{
			printf("\n Enter only the x co-ordinates for %s vertice : ",vrt_name[i]);
			scanf("%d",&vrt_x[i]);

    		}


		for(i=0 ; i<v ; i++)
    		{
			printf("\n Enter only the y co-ordinates for %s vertice: ",vrt_name[i]);
			scanf("%d",&vrt_y[i]);
    		}

		clrscr();


		/* For plotting points */


		for(i=0;i<v;i++)
		{
		      setbkcolor(0);
		      fillellipse(vrt_x[i],vrt_y[i],2,2);
		      outtextxy(vrt_x[i],vrt_y[i]-10,vrt_name[i]);
		}


		/* Adjancey Matrix */



		getch();
		return 0;
	}

	else
  	{
    		printf("Not enough memory\n");
    		return 1;
  	}





}
__________________
Parkour: A journey started by two & followed by many...
zegulas is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 29-08-2008, 12:00 PM   #2 (permalink)
Alpha Geek
 
Krazy_About_Technology's Avatar
 
Join Date: Jun 2004
Location: Noida - India
Posts: 765
Default Re: Graphics program in C

Dont you think you should input the vertices name (vrt_name[]) with a %c format specifier? %s might be pushing an extra NULL to the array writing in an out of bound area of memory.
__________________
Dell Inspiron 1525 - C2D 2 Ghz, 3GB, 250GB, X3100 :)

Samsung Omnia Pro B7610 with Stock WM 6.1 ROM

Blog: http://www.sumitbhardwaj.co.in/blog
Krazy_About_Technology is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My graphics card not Supporting Turbo C++ graphics plz help Maxx32 Graphic cards 1 19-06-2008 12:39 AM
Unable to run graphics program in C.. sauravgr8 Programming 18 23-09-2007 01:20 AM
new program in 'close program menu' list and more....... vishakadatta QnA (read only) 2 12-04-2005 11:33 PM
C++ Program Q. shwetanshu Programming 5 09-02-2005 01:50 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2