954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

coorect a C error m expected

typedef struct node node
struct
{ int

when i run the C program, compiler give me an error which is

, is expected,

help me

sara_84
Light Poster
25 posts since Dec 2007
Reputation Points: 14
Solved Threads: 0
 

If what you posted is what you're actually trying to compile, it's no surprise. No part of that code is valid.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

no, it is only part, and this is my code

#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<stddef.h>
#include <malloc.h>
/*#include<stack.h>*/

#define MAX 100
#define TRUE 1

typedef struct node node
	 struct 
	{   int   

long int graph[MAX][MAX];  /* = { { 0, 1 },/* 0 1 0 */
				/*{ 1, 1 }};2 0 0; */
int nodes;
int fnodes;
int counter2 = 0;
int counter = 0;//Start states
int myStack;
int start[MAX];
int final[MAX];
int V, E;
int visit[MAX];
char states[5];
int empty = TRUE;

int read()
{
  int a;
  int k;
  int b;
  nodes = -1;
  memset(states,0, sizeof(states));
  scanf("%d" ,&nodes);
  if (nodes <0)
  {
            return 0;
  }
  /*if(nodes == 0) */
    /*return 0;  */

  scanf("%d ", &fnodes);

  counter = 0;/*Start States*/
  counter2 = 0;/*Final States*/
  int cont;/*String Length*/
  for(a=0; a<fnodes; a++)
  {
     scanf("%d ",states);
     cont = -1;
     for(k=0; k<5; k++)
	  if(states[k] != '\0')
	     cont++;
	  else
	      break;

     /*printf("cont " , cont);
       printf(" %d ", *states);
       printf("%d ", states[0]);
       printf(" %d ", states[cont]); */
     int aux = 0;/*Sum of characters for Nodes   */
     int aux2 = 0;/*Sum of characters for Nodes*/
     int mult = 1;/*Multiple */

     if(states[cont]=='f')
     {
	  for(int k=cont-1; k>=0; k--)
	  {
	   /*printf(" -> %d " , states[k]); */
	    aux+=((int)states[k]- 48)*mult;
	    /*printf(" %d " ,aux);  */
	    mult*=10;
	  }

	 final[counter2++] = aux;
	 /*prinf(" %d ", final[counter2-1]);*/
     }
     else
     {
	  for(int k=cont-1; k>=0; k--)
	  {
	    /*printf(" -> %d", states[k]);*/
	    aux+=((int)states[k]-48)*mult;
	    mult*=10;
	  }
	 start[counter++] = aux;
     }
	 /*printf(" %d ",start[counter-1]);
	 //printf(" %d " ,counter ); */
  }

  for(a=0; a<nodes; a++)
  {
     for(b=0; b<nodes; b++)
     {
      scanf(" %d %d " ,graph[a][b]);
     }
  }
  if(counter>1)
     return -1;
  return 1;
}


void calc()
{
  int a;
  int b;

 for(a=0;a<30;a++)
 {
     for(b=0;b<30;b++)
     {
       if(a*b<100)
           graph[a][b]=0;
       else
          graph[a][b]=1;
     }     
 }
}
bool compareVertex(int v)
{
    
    int k;

    for(k=0; k<counter2; k++)
       if(final[k]==v)
       {
          /*printf(" %d , %d " ,final[k],v);*/
          return true;
       }
    return false;

}
void dfs(int vertex)
{
  int i;
  
  /*printf(" %d ",vertex);*/
  if(compareVertex(vertex))
     empty=false;

  visit[vertex] = 1;
  for (i=0;i<nodes;i++)
    if (!visit[i] && graph[vertex][i])
      dfs(i);
}
void bfs(int s) 
{
     int i, j, node;
     memset(visit, 0, sizeof(visit));
     myStack.push(s);
     
     while(!myStack.empty())
     {
          node = myStack.top();
          myStack.pop();
          if(visit[node]) continue;
          visit[node] = 1;

          for(i=0; i<V; i++)
               if(graph[node][i]) myStack.push(i);
     }
}
void print()
{
  int i,b; 

  for(a=0;a<nodes;a++)
   {
     for(b=0;b<nodes;b++)
     {
         printf(" %d  ",graph[a][b]);
     }

 }
}
int main() 
{
int j,h ;
int locuas = -1;

/*calc();*/
do
{
 locuas = read();//Check integer
  /*if(locuas == -1)
  {
     printf("This is not an DFA");
     continue;
  }*/
  if(locuas == 0)
     return 0;
/*print();*/
  for (i=0;i<nodes;i++)
      visit[i] = 0;
  for(h=0; h<counter;h++)
          dfs(start[h]);

  if(empty)
      printf("The Automata Language is Empty");
  else
      printf("The Automata Language is not Empty");
  
  empty = true;
      /*bfs(0);*/

}while(true);

 return 0;
}
sara_84
Light Poster
25 posts since Dec 2007
Reputation Points: 14
Solved Threads: 0
 
typedef struct node node struct { int


Is it obvious you are trying to define a structure type, but that's not the way of doing it.exempli gratia

typedef struct node
{
    int first;
    int second;
    int etc; /* i.e. char, floats, arrays, pointer or struct */
};

/* after that you can declare a variable of type node */

node my_node;
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

typedef struct node node

{ int a;

thanks, but the error is appears ( , expected)
tell me for what this error

sara_84
Light Poster
25 posts since Dec 2007
Reputation Points: 14
Solved Threads: 0
 

It's obvious you just found that code from somewhere on the net and your are desperately trying to make it work for you.

I would recommend starting from the beginning with your own code, because then they will be your own ideas and ultimately you will get a lot more out of it.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You