Not Yet Answered # how to generate a state transition diagram in c

Discussion Starter ashokkumarrsp Discussion Starter ashokkumarrsp Discussion Starter ashokkumarrsp Dave Sinkula 2,398 Discussion Starter ashokkumarrsp Dave Sinkula 2,398 Discussion Starter ashokkumarrsp Dave Sinkula 2,398 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

1

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

1

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

1

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.

1

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.

1

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

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..

1

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...?

1

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");
}
}
}
}
```

1

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.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...