how to generate a state transition diagram in c.. give me the implementation steps

What is a state transition diagram?

What is a state transition diagram?

the diagram which have states and is transform to the other state when the condition is satisfied.
eg: a---*-->b where a and b are states. when the condition * exists the state transform from a to b

So how do you draw this diagram in paper if a, b and * is given? Give me the steps.

So how do you draw this diagram in paper if a, b and * is given? Give me the steps.

A node is created for the state A & B. An arrow is directed from the state A to B.the transition happens only when the condition above the arrow is satisfied

So you want C only to draw this?

a---*-->b

So you want C only to draw this?

a---*-->b

yes sir.i need the code to include the nodes as user wish and to specify the conditions.

What is a state transition diagram?

http://en.wikipedia.org/wiki/Finite_state_machine

how to generate a state transition diagram in c.. give me the implementation steps

Can you show your initial attempt? This helps gauge what you can handle for a reply.

i have attempted to create a graph.such that i could include the nodes and make the transition between the nodes..

I meant code-wise. Do you have any sort of basic coding attempt?

I like function pointers, but I don't know if that's where you'd want to go based on the lack of code you have posted. Data structures you've created...? Etc...?

I meant code-wise. Do you have any sort of basic coding attempt?

I like function pointers, but I don't know if that's where you'd want to go based on the lack of code you have posted. Data structures you've created...? Etc...?

here is the code.. but i couldn run successfully.. an error "improper use of variable 'graph'"

#include<stdio.h>
#include<math.h>
int main()
{
   int a =0;
   typedef struct
   {
      int edges[20][20];
      int degree[21];
      int nvertices;
      int nedges;
   }graph;
   graph *g;
   read_graph(g,a);
   print_graph(g);



   read_graph(graph *g, int directed)
   {
      int i; /* counter */
      int m; /* number of edges */
      int x, y; /* vertices in edge (x,y) */
      initialize_graph(g);
      printf("enter the no of nodes and edges");
      scanf("%d %d",&(g->nvertices),&m);
      for ( i=1; i<=m; i++ )
      {
         printf("enter the value of nodes");
         scanf("%d %d",&x,&y);
         insert_edge(g,x,y,directed);
      }
   }
   initialize_graph(graph *g)
   {
      int i; /* counter */
      g -> nvertices = 0;
      g -> nedges = 0;
      for ( i=1; i<=20; i++ ) g->degree[i] = 0;
   }
   insert_edge(graph *g, int x, int y, int directed)
   {
      if ( g->degree[x] > 20 )
         printf("Warning: insertion(%d,%d) exceeds max degree\n",x,y);
      g->edges[x][g->degree[x]] = y;
      g->degree[x] ++;
      if ( directed == 0 )
         insert_edge(g,y,x,1);
      else
         g->nedges ++;
   }

/*delete_edge(graph *g, int x, int y, bool directed)
{
int i; /* counter */
/* for (i=0; i<g->degree[x]; i++)
if (g->edges[x][i] == y) {
g->degree[x] --;
g->edges[x][i] = g->edges[x][g->degree[x]];
if (directed == FALSE)
delete_edge(g,y,x,TRUE);
return;
}
printf("Warning: deletion(%d,%d) not found in g.\n",x,y);
} */
   print_graph(graph *g)
   {
      int i,j; /* counters */
      for ( i=1; i<=g->nvertices; i++ )
      {
         printf("%d: ",i);
         for ( j=0; j<g->degree[i]; j++ )
            printf(" %d",g->edges[i][j]);
         printf("\n");
      }
   }
#include<stdio.h>
#include<math.h>
   int main()
   {
      int a =0;
      typedef struct
      {
         int edges[20][20];
         int degree[21];
         int nvertices;
         int nedges;
      }graph;
      graph *g;
      read_graph(g,a);
      print_graph(g);



      read_graph(graph *g, int directed)
      {
         int i; /* counter */
         int m; /* number of edges */
         int x, y; /* vertices in edge (x,y) */
         initialize_graph(g);
         printf("enter the no of nodes and edges");
         scanf("%d %d",&(g->nvertices),&m);
         for ( i=1; i<=m; i++ )
         {
            printf("enter the value of nodes");
            scanf("%d %d",&x,&y);
            insert_edge(g,x,y,directed);
         }
      }
      initialize_graph(graph *g)
      {
         int i; /* counter */
         g -> nvertices = 0;
         g -> nedges = 0;
         for ( i=1; i<=20; i++ ) g->degree[i] = 0;
      }
      insert_edge(graph *g, int x, int y, int directed)
      {
         if ( g->degree[x] > 20 )
            printf("Warning: insertion(%d,%d) exceeds max degree\n",x,y);
         g->edges[x][g->degree[x]] = y;
         g->degree[x] ++;
         if ( directed == 0 )
            insert_edge(g,y,x,1);
         else
            g->nedges ++;
      }

/*delete_edge(graph *g, int x, int y, bool directed)
{
int i; /* counter */
/* for (i=0; i<g->degree[x]; i++)
if (g->edges[x][i] == y) {
g->degree[x] --;
g->edges[x][i] = g->edges[x][g->degree[x]];
if (directed == FALSE)
delete_edge(g,y,x,TRUE);
return;
}
printf("Warning: deletion(%d,%d) not found in g.\n",x,y);
} */
      print_graph(graph *g)
      {
         int i,j; /* counters */
         for ( i=1; i<=g->nvertices; i++ )
         {
            printf("%d: ",i);
            for ( j=0; j<g->degree[i]; j++ )
               printf(" %d",g->edges[i][j]);
            printf("\n");
         }
      }
   }
}

I hope I didn't screw up your actual code when I tried to put it in code tags, but it still looks like you may be defining a function within a function. And there appears to be much of the basics for C or C++ coding that might not know.

[edit]Taking another pass at what you posted, I seems to me that if you want to create on on-screen graphic representation of such a thing in C or C++ you are weeks/month/years away from doing so unless you have years/months/weeks of experience in another language already.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.