Jump to content

creating pie graph using c language

- - - - -

  • Please log in to reply
2 replies to this topic

#1
masangzkie

masangzkie

    Newbie

  • Members
  • Pip
  • 1 posts
Hello guys, I have a project about c programming. Is there any resources where can i find a source code about creating pie graph using c language? I need some help here, our Prof. did not discuss it properly, I don't understand him.

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
In C you can use Allegro (Allegro tutorial) or SDL.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
I am making a program for having a graph in C.I am having some problem in making it.please see my code and let me know what is the problem I am doing the same it is not a home work problem in my case.So you can use my code.
Following file is graph.c

#include "declarations.h"

graph root = NULL;


int main()

{

	cgraph();

}


void cgraph(void)

{

	int n, choice, dir, count;


	choice = 1;

	count = 1;

	graph priv, temp;


	printf("Printf we are making a graph the first is root node\n");

	while (choice == 1) {

		count++;

		if (count == 1) {

			printf("This is going to be root node \n");

			scanf("%d", &n);

			root = cnode(n);

			count--;

			priv = root;

		}		//ending if

		else {

			printf ("Enter direction you want to go LEFT 1 RIGHT 2 TOP 3 DOWN 4\n");

			scanf("%d", &dir);

			printf("Enter the data  for graph node\n");

			scanf("%d", &n);

			temp = cnode(n);

			if (dir == 1) {

				priv->LEFT = temp;

			}

			if (dir == 2) {

				priv->RIGHT = temp;

			}

			if (dir == 3) {

				priv->TOP = temp;

			}

			if (dir == 4) {

				priv->DOWN = temp;

			}

			priv = temp;

		}		//ending else

		printf ("Enter 1 to continue adding nodes to graph any thing else would take you out\n");

		scanf("%d", &choice);

	}			//ending while

}				//ending main


graph cnode(int data)

{

	graph temp = (graph) malloc(sizeof(graph));


	temp->data = data;

	temp->LEFT = NULL;

	temp->RIGHT = NULL;

	temp->TOP = NULL;

	temp->DOWN = NULL;

	temp->color = -1;

	return temp;

}


qnode travel_graph(graph rh)

{

 qnode qt;

 if(rh->LEFT)

 {

 qt= cque(rh);

 }

 if(rh->RIGHT)

 {

 qt=cque(rh);

 }

 if(rh->TOP)

 {

 qt=cque(rh);

 }

 if(rh->DOWN)

 {

 qt=cque(rh);

 }

return qt;

}


Following file is declarations.h

#include<stdio.h>

#include<stdlib.h>

#define GREY 1

#define BLACK 0

#define WHITE 2


struct node {

	int data, color;

	struct node *LEFT, *RIGHT, *TOP, *DOWN;

};//this structure defines a node of the graph


struct stack {

struct stack *priv;

struct node *graph_node;

};// this is to define a structure which should hold node of a structure


struct que1 {

struct stack *next;

struct node *graph_node;

}

typedef struct node * graph;

typedef struct stack * snode;

typedef struct que1 * qnode;

graph cnode(int data);		//cnode is to create a node for graph

void cgraph(void);

extern snode sroot;

extern int stack_counter;

extern int que_counter;

extern qnode qroot;

void travel_graph(void)

Following file is que.c

#include<declarations.h>

qnode cque(graph temp);

qnode quepop(qnode stemp);

qnode cquenode(graph gtemp);

int que_counter = 0;


qnode qroot = NULL;

qnode cque(graph gtemp)	//cque is to create que it returns a pointer which would point to top of que

{

	qnode spriv,some;

	if (que_counter == 0) {

		qroot = cquenode(gtemp);

		spriv = sroot;

		que_counter++;

	} else {

		some = cquenode(gtemp);

		some->next = spriv;

		spriv = some;

	}

       return spriv;

}


//struct que is representing a que

//struct node is representing a node in graph


qnode cquenode(graph gtemp)

//this function should create a node of the que which should be storing the graph node as a pointer

{

	qnode an;

	an = (qnode) malloc(sizeof(qnode));

	an->graph_node = gtemp;

	an->priv = NULL;

	return an;

}


qnode quepop(qnode stemp)

{

   qnode temp;

   temp =stemp;

   stemp=stemp->priv;

   free(temp);

   return stemp;

}


following file is stack.c

#include<declarations.h>

snode cstack(graph temp);

snode stackpop(snode stemp);

snode cstacknode(graph gtemp);

int stack_counter = 0;


snode sroot = NULL;

snode cstack(graph gtemp)	//cstack is to create stack it returns a pointer which would point to top of stack

{

	snode spriv,some;

	if (stack_counter == 0) {

		sroot = cstacknode(gtemp);

		spriv = sroot;

		stack_counter++;

	} else {

		some = cstacknode(gtemp);

		some->priv = spriv;

		spriv = some;

	}

       return spriv;

}


//struct stack is representing a stack

//struct node is representing a node in graph


snode cstacknode(graph gtemp)

//this function should create a node of the stack which should be storing the graph node as a pointer

{

	snode an;

	an = (snode) malloc(sizeof(snode));

	an->graph_node = gtemp;

	an->priv = NULL;

	return an;

}


snode stackpop(snode stemp)

{

   snode temp;

   temp =stemp;

   stemp=stemp->priv;

   free(temp);

   return stemp;

}

I would suggest you help me to improve my code that will help you do your assignment.
My code is having the problem
1) graph.c the function cgraph does not create graph properly.
For example if I add a node
A->B
I will not be able to do
C
^
|
A->B

Help me to improve my code this well help you also.
It has been more than 2 weeks I am trying to improve this code and at a lot of places I was stuck up.I am trying to make code so that I can do BFS,DFS and and then using my programs I can run algorithms given in book of coreman.
Let it be a simple program and then we can keep modifying and improving.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users