I have the following function. in this function i am not able to push back in vector.
I will explain how it works. if same f_pin will comes in the second iteration compared to first iteration of EventNum loop it will get into if Loop and have to push into opNo vector, if different fpin will come in second iteration it has to enter else loop and push in other vector..

I did all conditions but i am not getting how to push in separate vectors.. I am trying from past 2 days, struckked here. Any one plz help. the code is as follows.

the print statement is giving correct values..

void InitFbNode()
{
SUCCNODE *succ;
succ=(struct SUCCNODE *)malloc(sizeof(SUCCNODE));
for(int FBNum=0;FBNum<fbnodeLst.size();FBNum++)
{
 if(fbnodeLst[FBNum].fbInfo->fb_str->output_event_cnt>0)
{
for(int EventNum=0;EventNum<fbnodeLst[FBNum].fbInfo->fb_str->output_event_cnt;EventNum++)
{
 int FirstNo=fbnodeLst[FBNum].fbInfo->eventLink[0].f_pin;
 succ->pinNo=fbnodeLst[FBNum].fbInfo->eventLink[EventNum].f_pin;
//same f_pin comes in the 2nd loop push into the same vector, i.e same in first fpin vector
if(succ->pinNo==FirstNo)
{
printf("pinNo %d:%d\n",EventNum, succ->pinNo);				
printf("NO:%d\n", fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
////here have to push in vector
//succ->opNo.push_back(fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
}				
else
// different f_pin will come in 2nd loop push into another vector
{
//here have to push in vector
//succ[succ->pinNo].opNo.push_back(fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
printf("%d:%d\n",EventNum, succ->pinNo);	
}
fbnodeLst[FBNum].succNodeNo.push_back(*succ);
			}
		}				
	}

Structure declaration isa as follows.

struct SUCCNODE{
	int pinNo;
	vector<unsigned long>opNo;
};

struct LINK{
	unsigned short	no;		
	unsigned short	pin;	
	unsigned short	f_pin;	
};




struct FB_STR{
    unsigned long	fbCode;	 			
	unsigned long	wait_event;			
	unsigned char	wait_type;			
	unsigned char	pinCnt;				
	unsigned short	output_event_cnt;	
	unsigned short	breakpoint;		  
	unsigned short	property_cnt;		
};

struct FB_INFO{
	FB_STR	*fb_str;				
	unsigned int *dataLink;					
	LINK	*eventLink;						
	unsigned long	*property;				
};


typedef struct{
	int	Offset;
	int	Bytes;
	int	page_no;	
} FBD_FILE_POS;
 

/* FBノード	*/

struct FB_NODE
{
	unsigned long nodeNo;           
	vector<unsigned long> predNode;    
	vector<SUCCNODE> succNodeNo;	
	unsigned long analyzFinFlag;	  
	unsigned long fbNo;		          
    unsigned long blockStartFlag;	 
	unsigned long sourceNode;	       
	unsigned long feedbackFlag;	    
	FB_INFO	*fbInfo;		          
};

void InitFbNode();				
vector<FB_NODE> fbnodeLst;		
void DispFBTable();

Recommended Answers

All 4 Replies

It's a funny mix of C and C++ languages. It stands you in bad stead.
The malloc does not call allocatable object contructor. So after

succ=(struct SUCCNODE *)malloc(sizeof(SUCCNODE));

you have an uninitialized memory slot for a structure SUCCNODE object but NO ready-to-use vector<unsigned long>opNo member in this structure!
Please, avoid using old good malloc() when you write C++ program (and forgert free() too).
Create objects with new operator, delete them with delete operator:

SUCCNODE* succ = new SUCCNODE;

Correct source then try again.

Memory allocation is not my problem. I want to push in separate vectors. How i have to push into vectors in line no 18 and line 24.. Even i corrected the code with new operator, but for push into vector, i dont know to create separate vectors

void InitFbNode()
{
SUCCNODE *succ=new SUCCNODE;
for(int FBNum=0;FBNum<fbnodeLst.size();FBNum++)
{
 if(fbnodeLst[FBNum].fbInfo->fb_str->output_event_cnt>0)
{
for(int EventNum=0;EventNum<fbnodeLst[FBNum].fbInfo->fb_str->output_event_cnt;EventNum++)
{
 int FirstNo=fbnodeLst[FBNum].fbInfo->eventLink[0].f_pin;
 succ->pinNo=fbnodeLst[FBNum].fbInfo->eventLink[EventNum].f_pin;
//same f_pin comes in the 2nd loop push into the same vector, i.e same in first fpin vector
if(succ->pinNo==FirstNo)
{
printf("pinNo %d:%d\n",EventNum, succ->pinNo);				
printf("NO:%d\n", fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
////here have to push in vector
//succ->opNo.push_back(fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
}				
else
// different f_pin will come in 2nd loop push into another vector
{
//here have to push in vector
//succ[succ->pinNo].opNo.push_back(fbnodeLst[FBNum].fbInfo->eventLink[EventNum].no);
printf("%d:%d\n",EventNum, succ->pinNo);	
}
fbnodeLst[FBNum].succNodeNo.push_back(*succ);
			}
		}				
	}

It was (one of) your problem because with malloc you have no any vector in SUCCNODE.
The second problem (see *** mark):

for (int EventNum=0; ... ;EventNum++)
{ 
    int FirstNo=fbnodeLst[FBNum].fbInfo->eventLink[0].f_pin; // *** Local FirsNo
    succ->pinNo=fbnodeLst[FBNum].fbInfo->eventLink[EventNum].f_pin;
    //same f_pin comes in the 2nd loop push into the same vector,
    // i.e same in first fpin vector
    if (succ->pinNo==FirstNo) { // *** the same FirstNo on every circuit
       ...

The loop body is a block. All inner declarations elaborated on the every circuit of the loop. So your program don't know what's a previous f_pin value. I don't know what you want to do with the 1st f_pin (no predecessor).
Possible solution (one of):

int prevNo = ...[0].pin; // or any impossible pin
for (...)
{
      if (succ->pinNo == prevNo) {
         // the same pinNo; do this...
      }
      else // another pinNo
      {
          // different pinNo; do that...
          prevNo = succ->pinNo; // for the next loop
      }
...

The third problem:
I can't understand what's your "other vector" (and you? ;)). It's not a problem to create a new vector, but when and where to do it?

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.