ambarisha.kn 15 Junior Poster in Training
/*decimal to binary*/
#include <stdio.h>

void printBinary(const unsigned char val) {

  for(int i = 7; i >= 0; i--)

    if(val & (1 << i))

     printf("1");

    else

      printf("0");
  printf("\n");

} 

int main() {
	int dec;
	int hold=0;
	printf("Integer number : ");
	scanf("%d",&dec);
	printBinary((unsigned char)dec);	
}
Hiroshe commented: 1. Don't give away free code. 2. That code is bad. -1
ambarisha.kn 15 Junior Poster in Training

Question: Declare a pointer to a function taking an int argument and returning a pointer to a function that takes a char argument and returns a float.

I did code as follows. But it is giving error. Please correct this.

#include <iostream>
using namespace std;

float func(int x)(char c) {
  cout << "func() called..." << endl;
}


int main() {
  int x = 2;
   char c;
  float (*(*fp)(int))(char); // Define a function pointer
  (*fp) = func;  // Initialize it
  (*(*fp))(x)(c);    // Dereferencing calls the function 
}
ambarish@ubuntu:~/exercise$ g++ ex33.cpp
ex33.cpp:4: error: ‘func’ declared as function returning a function
ex33.cpp: In function ‘int main()’:
ex33.cpp:13: error: assignment of read-only location ‘* fp’
ex33.cpp:13: error: cannot convert ‘int ()(int)’ to ‘float (* ()(int))(char)’ in assignment
ambarish@ubuntu:~/exercise$
ambarisha.kn 15 Junior Poster in Training

If you can't figure out code tags after 60+ posts, what makes you think kernel programming is for you?

who the hell are you, you are not the person to speak about ability.
Ofcourse i am not brillinat than you, but u have some manners.
First learn how to behave.

If you dont know manners, your knowledge is waste.

I know how to use tags, but in hurry i have not used tags.
Thats it.

If you know answer reply to the post else dont blame others.
I think For this purpose u made 5000+ posts.

Salem commented: I couldn't give a shit about the code if you can't be arsed to use code tags. -7
ambarisha.kn 15 Junior Poster in Training

HI,

I new to linux device drivers.
I am developing HDLC driver.
I dont know how to read and write data in memory mapped address.
Please help.

/*code*/

#define REG_MAP_ADDR 0x50400000

/* Registers */
typedef struct {
u16 MOD;
u16 STATUS;
u16 TBASE;
u16 Tx;
u16 TxBD;
u16 RBASE;
u16 MAX_BUFF_LEN;
u16 Rx;
u16 RxBD;
}reg_map_1ch_t;

typedef struct {
reg_map_1ch_t reg_ch[16];
}reg_map_t;


reg_map_t *reg_map;
unsigned short data=0;
volatile unsigned short *base_addr;

reg_map = ioremap_nocache(REG_MAP_ADDR, sizeof(reg_map_t));

/*now i have to read and write the data of memory mapped address.
Give me idea. I did as follows */

base_addr = (volatile unsigned short *)reg_map;
data = (unsigned short)(*(base_addr));
printk(KERN_ALERT "Before Write Read Data: %d\n", data);

data = 1;
base_addr[0] = data;

data = (unsigned short)(*(base_addr));
printk(KERN_ALERT "After Write Read Data: %d\n", data);

I did Above code in init module, when i am inserting the module, system will reboot.
Whats the error.
i am not getting error, just reboots the system.

ambarisha.kn 15 Junior Poster in Training

Hi,
I am new to Linux device driver, i am developing HDLC-ip driver.
i dont know how to do memory mapping.
Please guide me how to do memory map.
Please find an attachment with this for list of registers and memory map table.

ambarisha.kn 15 Junior Poster in Training

dont know how to use. tell me how?

ambarisha.kn 15 Junior Poster in Training

Here, how i am writing log to a file.
Its giving error only for some time. It may or may not give error as "Some other process using this file".

How to rectify this. Is it possible to wait untill other process release this file.

public void WriteLog(LogType type, LogStatus status, string message, params object[] args)
        {
            DateTime now = DateTime.Now;

            string path = GetPath(type, now);

            string appname;
            string usrname;

            if (AppService.Provider.CurrentAppType == null)
                appname = "-";
            else
                appname = AppService.Provider.CurrentAppType.ToString();

            if (UserService.Provider.CurrentUser == null)
                usrname = "-";
            else
                usrname = UserService.Provider.CurrentUser.Name;

            appname = (appname + new string(' ', 10)).Substring(0, 10);
            usrname = (usrname + new string(' ', 16)).Substring(0, 16);

            string line = now.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture) + " " +
                          status.ToString().Substring(0, 1) + " " +
                          appname + " " +
                          usrname + " " +
                          string.Format(CultureInfo.InvariantCulture, message, args) + Environment.NewLine;

            lock (_lck)
            {
                File.AppendAllText(path, line);
#if DEBUG
                Console.Write(line);
#endif
            }
        }
ambarisha.kn 15 Junior Poster in Training

How to wait for some time while writing to a file.

I am appending some text in log file, its giving error as Some other process using this file.

How i have to wait untill its free.

ambarisha.kn 15 Junior Poster in Training

if we use activate event, it will go infinite. not able to minimize of form1 or close of form1.

ambarisha.kn 15 Junior Poster in Training

I have mentioned so many times, minimize and maximize is not a aproblem for me.

I already wrote this code for minimize and maximize of both forms and working fine, but the problem is as follows.

Form1 and form2 both in normal mode.
if i click on 3rd window, both form1 and form2 will go behind that 3rd window.

Again if i want to see form1 and form2, i have to click on form1, so that both forms have to come front of third window and have to visible of both form1 and form2.

I hope u understood my question.

ambarisha.kn 15 Junior Poster in Training

I want form2 should be in top, when form1 is also in top of other windows. To do this which event i have to call??

i.e if i click form1, both forms have to appear if it is behind the other windows.

ambarisha.kn 15 Junior Poster in Training

@cVz:
I didnt get you, will u please explain in brief.

Just minimize and maximize the form you want on top ...l it will work ...

ambarisha.kn 15 Junior Poster in Training

But i want event, when form1 come to front, to make form2 as topmost.

Need Event of form1, to make form2 as topMost.
when form1 come front from back screen.

ambarisha.kn 15 Junior Poster in Training

i dont have problem in minimizing,maximizing, Show and close. How to bring to front of the form2 when form1 activates.

I want only one operation.

When form1 is in normal state but behind another window, if we click that form1, form2 also have to come front along form1.


How to do this? Is it possible using tag itself. I dont have any buttons in the form.Please give me the solution for this.


Which event i have to call when form1 came front.

I want to do every operation of form1 reflects on form2.

minimize , maximize, normal, BringToFront, close etc...

All are working except Bring2Front.
Please suggest me the solution in simple way.

ambarisha.kn 15 Junior Poster in Training

I have 2 forms.
Form2 has no minimum, max, close icons.
Form2 have to control by form1.

i.e minimize of form1 becomes form2 minimize.
normal of form1 becomes form2 normal.
closing of form1 becomes form2 close.

All these are working.

but when form1 is behind the screen, i.e if form1 activates, form2 have to come front.

I have wrote activate event for this.
In this i have problem, if we use form activate event, when we click for minimize of form1, it calls form1 activate event and activates form2, but not minimize. It will go to infinite.

How to activate form2 when form1 activates, but when we minimize form1, form2 also have to minimize.

Form2= _rptForm

protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0112) // WM_SYSCOMMAND
            {
                if (m.WParam == new IntPtr(0xF020)) //SC_MINIMUM
                {
                    _rptForm.WindowState = FormWindowState.Minimized;
                }

                if (m.WParam == new IntPtr(0xF120))       //SC_RESTORE
                {
                    _rptForm.WindowState = FormWindowState.Normal;
                }
               
                m.Result = new IntPtr(0);
            }
            base.WndProc(ref m);
        }

        private void DataBoxDlg_Activated(object sender, EventArgs e)
        {

            _rptForm.Activate();
        }

Please change this code to work all which i mention above.

ambarisha.kn 15 Junior Poster in Training

I am trying to do localization of ColumnHeadersDefaultViewStyle property of DataGridView.I need localization in both Japanese and English.
While designing the form, i set the Font Style of ColumnHeadersDefaultViewStyle property of DataGridView to "Arial" and changed the Form Language property to "japanese" and set the Font style of ColumnHeadersDefaultCellStyle property to" MS UI Gothic" Fontfamily.
But the problem is when i switch over to default language,the Font value of ColumnHeadersDefaultViewStyle property of DataGridView holds the "MS UI Gothic" family rather than "Arial".
can anyone give suggestions for this problem...

ambarisha.kn 15 Junior Poster in Training

Its so simple, we have to write "wb" in fwrite instead of "w" , while writing binary file.

FILE *f1;
f1=fopen("c:\\ambi.dat", "wb");
fwrite(constDataArea, 1,4, f1); 	
fclose(f1);

I did changes as above and i got output..

ambarisha.kn 15 Junior Poster in Training

Consider d_type=POINT_LONG in the following program.
and data.Long=0xA;

In the following program i am getting correct output in constDataArea[0],constDataArea[1],constDataArea[2], constDataArea[3]
which is oxA, 0x0, 0x0, 0x0.

But not able to write the same into ambi.dat file. Some junk value is inserting in the front.
and writing 5 bytes instead of 4 bytes.
Output file(ambi.dat)is as follows
-----------------
0D 0A 00 00 00
-----------------

Expected output in dat file is
---------------
0A 00 00 00
--------------
What is the error in this code. plz give me suggestion

char *constDataArea;
const size_t BUFSIZE = 1024*1024;	
constDataArea=(char *)malloc(BUFSIZE);
size_t datasize=0, nextpos=0, freepos=0;
for(int nv_data=0,indx=0;nv_data<nonVoltleData;nv_data++)
{
switch(d_type)
{
	case POINT_BOOL:
			data.Bool=(char)tmpbuf[index+2+nv_data+indx];				
			fprintf(out_fp,"\nBool Data1:%x\n", data.Bool);
			datasize=1;
			
			nextpos=freepos+datasize;
			memcpy(constDataArea+freepos,(char *)&data.Bool, datasize);   /*data.bool から ConstDataArea にコピー*/
			freepos=nextpos;
			break;
	case POINT_CHAR:
			data.Char=(char)tmpbuf[index+2+nv_data+indx];
			fprintf(out_fp,"\nChar Data1:%x\n", data.Char);
			datasize=sizeof(data.Char);
			
			nextpos=freepos+datasize;
			memcpy(constDataArea+freepos,(char *)&data.Char, datasize);		/*data.Char から ConstDataArea にコピー*/
			freepos=nextpos;
			break;
	case POINT_SHORT:
			data.Short=(short)tmpbuf[index+2+nv_data+indx];
			fprintf(out_fp,"\nShort Data1:%x\n", data.Short);
			datasize=sizeof(data.Short);
			
			if(freepos % sizeof(data.Short))
			{
				freepos+= sizeof(data.Short)-freepos % sizeof(data.Short);
			}
			nextpos = freepos + datasize;
			fprintf(out_fp,"S:ConstArea:%d\tfreepos:%d\n", constDataArea, freepos);
			memcpy(constDataArea+freepos,(char *)&data.Short,datasize);		/*data.Short から ConstDataArea にコピー*/
			freepos=nextpos;
			break;
	case POINT_LONG:
			data.Long=(long)tmpbuf[index+2+nv_data+indx];
			fprintf(out_fp,"\nLong Data1:%x\n", data.Long);
			datasize=sizeof(data.Long);
			
			if(freepos % sizeof(data.Long))
			{
				freepos+= sizeof(data.Long)-freepos % sizeof(data.Long);
			}
			nextpos=freepos+datasize;
			memcpy(constDataArea+freepos,(char *)&data.Long, datasize);		/*data.Long から ConstDataArea にコピー*/
			freepos=nextpos;
			break;
	case POINT_FLOAT:
			data.Float=*(float*)&tmpbuf[index+2+nv_data+indx];
			fprintf(out_fp,"\nFloat Data1:%f\n", data.Float);
			datasize=sizeof(data.Float);
			
			if(freepos % sizeof(data.Float))
			{
				freepos+= sizeof(data.Float)-freepos % sizeof(data.Float);
			}
			nextpos=freepos+datasize;
			memcpy(constDataArea+freepos,(char *)&data.Float, datasize);	/*data.Float から ConstDataArea にコピー*/
			freepos=nextpos;
			break;
	case POINT_DOUBLE:
			data.Double = *(double*)&tmpbuf[index+2+nv_data+indx];
			fprintf(out_fp,"\nDouble Data1:%lf(0x%0x)\n", data.Double, data.Double);
			datasize=sizeof(data.Double);
		
			if(freepos % sizeof(data.Double))
			{
				freepos+= sizeof(data.Double)-freepos % sizeof(data.Double);
			}	
			nextpos=freepos+datasize;
			memcpy(constDataArea+freepos,(char *)&data.Double, datasize); …
ambarisha.kn 15 Junior Poster in Training

Thanks Salem, I got it..

Actually i was confused with offset and address. Now i got it what is offset.

My code is working fine..
Code is as follows.
please suggest me if there is any better idea than the following code..

void create_fbeCodeDat()
{
	int checkSum=0;
	unsigned int totBufSize=0;
	vector<unsigned int>offset;
	fwrite(&signature,1, 4, bin_fp);//signature=0xabcd0001
	fwrite(&version, 1,4,bin_fp);	//Version番号
	fseek(bin_fp,4,SEEK_CUR); 	//FBDプログラムコード,	FBDパラメータサイズ
	fseek(bin_fp,2,SEEK_CUR);	     //未使用(未定義)
	fwrite(&fbdStepno,1,2,bin_fp);	//FBDステップ数[N1]
	fseek(bin_fp,4,SEEK_CUR);	//定数データへのオフセット
	fseek(bin_fp,fbdStepno*4,SEEK_CUR);	//FBDステップ オフセット	

	unsigned int fbdStepOff=fbdStepno*4;//initial constant
	offset.push_back(fbdStepOff); //Offset for FBD step 0
	
	/*ブッファにあるFB毎の実行コードの追加*/
	for(int buf=0; buf<buffList.size();++buf)
	{
                //offset for fbd steps 1 to (n-1), adding size and initial constant
		fbdStepOff+= buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
		offset.push_back(fbdStepOff);	
		fwrite(buffList[buf].fbCodeAddr,1,buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr, bin_fp);
		//printf("Buff FBCODEADDr:0x%x Buff tmpAdr:0x%x\n", buffList[buf].fbCodeAddr, buffList[buf].tmpAddr);
		totBufSize+=buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
	}
	fseek(bin_fp, -(totBufSize+fbdStepno*4), SEEK_CUR);
	for(int off=0;off<offset.size();++off)
	{	
		fwrite(&offset[off], 1,4,bin_fp);
	}
	fseek(bin_fp, totBufSize, SEEK_CUR);
	fwrite(&checkSum,1,4,bin_fp);	//sum値
}
Salem commented: Well done! +23
ambarisha.kn 15 Junior Poster in Training

How to get the current address. Actually first i leave some empty space to write the offset address.
After writing data from buffer, i have to calculate the offset address and have to write back the offset address..

i will give you the picture, how i have to write dat file.
see atachment..

ambarisha.kn 15 Junior Poster in Training

>i want to write forward pointer address in present pointer field.
If I understand your problem correctly, you have two immediate options:

  1. Get the current address, then offset it by the known amount and write it.
  2. Seek forward, save the current address, then seek back and write it.

How to get the current address

ambarisha.kn 15 Junior Poster in Training

I wrote the following function and it is working fine, but my problem is i want to write forward pointer address in present pointer field.

I will explain in code.
please check line numbers 10, 11, 12, 13 in the following code..

void create_fbeCodeDat()
{
	int checkSum=0;
	fwrite(&signature,1, 4, bin_fp);//signature=0xabcd0001
	fwrite(&version, 1,4,bin_fp);//Version番号
	fseek(bin_fp,4,SEEK_CUR);	 //FBD Program code
	fseek(bin_fp,2,SEEK_CUR); //not used
	fwrite(&fbdStepno,1,2,bin_fp); //FBD step No.[N1]
	fseek(bin_fp,4,SEEK_CUR);	 //const data offset
//Here i have to write the address of next fbdstepno*4+1 bytes
//consider fbdstepno=4, here in 4 bytes have to write address of 5th byte address
// for ex: next 5th byte adress has to be write here in 4 bytes
//fwrite( addr(5th byte), 1,4, bin_fp);   //how to write 1st argument
// actually in the program here i have to write the address of buffList[buf].fbCodeAddr in 4 bytes. for buf=0, have to write bufflist[0].fbCodeAddr in 4 bytes
 //        for buf=0 and 1, have to write bufflist[0].fbCodeAddr in 4 bytes, and    bufflist[1].fbCodeAddr in 4 bytes
//and so on... and next the following code continues..
	
	for(int buf=0; buf<buffList.size();++buf)
	{
		fwrite(buffList[buf].fbCodeAddr,1,buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr, bin_fp);
	}
	fwrite(&checkSum,1,4,bin_fp);//sum値
}
ambarisha.kn 15 Junior Poster in Training

Pass them in as pointers from your calling function.

void fbExeCode(int BldCnt, char* fCodeAddr, char* tmpAddr){

}

A few things to be careful about. If you want to allocate them in fbExeCode, then initialize them to NULL to be safe. Also make sure you don't lose the starting memory location, so you may want to use a temp pointers variable to move through your buffers.

i tried that one, but it was giving error aschange of char ** to char* is not possible

ambarisha.kn 15 Junior Poster in Training

I wrote the following function. i want to return fbCodeAddr and tmpAddr to the main function.

How to do this?

Function is as follows;

void fbExeCode(int BldCnt)
{
//	for(int BldCnt=0;BldCnt<fbdStepno; BldCnt++)
	{
		char *fbCodeAddr;
		char *tmpAddr=0;
		char *buffer;
		int n;
		fbCodeAddr=(char *)malloc(1024);
		int stack=0;
		int totalPin=0;
		for(int fb=0;fb<fbnodeLst.size();fb++)
		{
			totalPin+=fbnodeLst[fb].fbInfo->fb_str->pinCnt;		
		}
		//printf("BLD:%d PIN:%d\n ", BldCnt,totalPin);
		memcpy(fbCodeAddr, (char *)&BldCnt,4);
		memcpy(fbCodeAddr+4, (char *)&stack,4);
		memcpy(fbCodeAddr+8, (char *)&totalPin,4);	
		tmpAddr = fbCodeAddr+12;
	//	printf("ORDER SIZE:%d\n", orderList.size());
		for(int OL=0; OL<orderList.size();++OL)
		{			
			tmpAddr+=4;
			memcpy(tmpAddr, (char *)&orderList[OL].fbCode,4);
			for(int ip=0; ip<orderList[OL].ipAdr.size();++ip)
			{
				tmpAddr+=4;				
				memcpy(tmpAddr, (char *)&orderList[OL].ipAdr[ip],4);
			//	printf("IP Adress %d:0x%x\n" ,ip+1, orderList[OL].ipAdr[ip]);
			}
			for(int op=0;op<orderList[OL].opAdr.size();++op)
			{
				tmpAddr+=4;				
				memcpy(tmpAddr, (char *)&orderList[OL].opAdr[op],4);
				//printf("O/P Adress :0x%x\n\n", orderList[OL].opAdr[op]);
			}
		}
		printf("Total bytes Used:%d Bytes\n", tmpAddr+4-fbCodeAddr);
		printf("fbcodeAddr:0x%x \n", *(fbCodeAddr+8));
	}
}
ambarisha.kn 15 Junior Poster in Training

Thanks i got my mistake.

ambarisha.kn 15 Junior Poster in Training

DB DC etc also need to be char* as well.
As does your baseAddrTable, it too needs to be an array of char*

But if i make DB, DC as char its not possible to add 1024.

then how to add 1024 bytes to that

ambarisha.kn 15 Junior Poster in Training

Hi,

I am allocating memory for some areas. For DB i need 1024 bytes, for DS 1024*2 bytes and so on, and i initialised address as follows.

I initailise devBaseAddr to DB, because DB comes first, and next DC. DB is 1024 bytes , so for DC=DB+1024. This is DC address.

But there is an error in intialisation of DB address.
i.e in Line 8

DB=devBaseAddr;

Because devBaseAddr is of type char and DB is of type size_t.

How to assign address for DB i.e starting address of devBaseAddr;

void deviceBaseAddr()
{
	char *devBaseAddr;
	const size_t TotalDevMem = 1024+1024+1024*2+1024*4+1024*4+1024*8+1024*8+1024*8+1024*8+1024*8;  /*DB+DC+DS+DL+DF+DD+D+M+X+Y*/
	size_t DB, DC, DS, DL, DF, DD, D, M, X, Y;
	devBaseAddr=(char *)malloc(TotalDevMem);
	
	DB = devBaseAddr;
	DC = DB+1024;
	DS = DC+1024;
	DL = DS+1024*2;
	DF = DL+1024*4;
	DD = DF+1024*4;
	D = DD+ 1024*8;
	M = D + 1024*8;
	X = M + 1024*8;
	Y = X + 1024*8;
	size_t baseAddrTable[10] = { DB, DC, DS, DL, DF, DD, D, M, X, Y };

}
ambarisha.kn 15 Junior Poster in Training

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);
			}
		}				
	}
ambarisha.kn 15 Junior Poster in Training

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 …
ambarisha.kn 15 Junior Poster in Training

Before i was opened the file as follows.

out_fp = fopen(oppath,"wb");

i am not writing into dat file. I am writing to text file. so i changed the code as follows and its working fine.. thanks

out_fp = fopen(oppath,"w");
ambarisha.kn 15 Junior Poster in Training

Hi everybody,

I want to write enter in a text file. How to do this. I wrote the code as follows. see if i write like this, it is printing one special character like arrow. I want to print in the following line, instead it is printing in single line with arrow.

How to do next line in the file write..

fprintf(out_fp,"----------------------------------------------------------\n");
fprintf(out_fp,"\tFBNO  FBCode         入力FB番号    出力FB番号  \n");
fprintf(out_fp,"----------------------------------------------------------\n");
ambarisha.kn 15 Junior Poster in Training

Thnaks. Its working fine

ambarisha.kn 15 Junior Poster in Training

I have input files like this
a.iup
b.iup
c.iup.......

i have these input files in a variable called fname;
like this

char *fname="c:\\iupfiles\\a.iup";
every time i will get file name in this variable. But how to concatenate the variable with some other name like as follows in output file name.

in a loop i will get one file at one time. I have write the output into file for each input file as
a_res.txt
b_res.txt
c_res.txt...

like this. How to do this..

ambarisha.kn 15 Junior Poster in Training

Thanks its working fine

ambarisha.kn 15 Junior Poster in Training

I want to read all files in a particular folder using C programming. HOw to do this. Thanks.

Ex: I have some 5 files in folder named c:\temp.
I want to read all files one after another and want to write output file for each input file.
The output files has to be saved in another folder named c:\output

How to do this. Plz any one give me suggestion how to start

ambarisha.kn 15 Junior Poster in Training

Well the first thing would be to learn some indentation and spacing skills, so that the code is more readable.
Eg

char *constDataArea;
    data.Short=5;
    data.Long= 6;
    data.Char=1;

    const size_t BUFSIZE = 1048576;
    size_t datasize=0, nextpos=0, freepos=0;

    constDataArea=(char *)malloc(BUFSIZE);

    if (nextpos > BUFSIZE)
    {  
        printf("Out of memory\n");
        exit(0);
    }
    datasize=sizeof(data.Char);
    nextpos=freepos+datasize;
    memcpy(constDataArea+freepos,(char *)&data.Char, datasize);
    freepos=nextpos;
    
    if (nextpos > BUFSIZE)
    {  
        printf("Out of memory\n");
        exit(0);
    }
    datasize=sizeof(data.Long);

    if(freepos==1 || freepos%4==1)
    {
        freepos+=3;
    }
    else if(freepos==2 || freepos%4==2)
    {
        freepos+=2;
    }
    else if(freepos==3 || freepos%4==3)
    {
        freepos+=1;
    }

    nextpos = freepos + datasize;					
    memcpy(constDataArea+freepos,(char *)&data.Long,datasize);
    freepos=nextpos;
    
    if (nextpos > BUFSIZE)
    {  
        printf("Out of memory\n");
        exit(0);
    }						 
    
    datasize=sizeof(data.Short);
    if(freepos%2==1)
    {
        freepos+=1;
    }
    nextpos=freepos+datasize;
    memcpy(constDataArea+freepos,(char *)&data.Short, datasize);
    freepos=nextpos;
    
    printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[4], constDataArea[6]);

> How to change the code to get the output in the above indexes.......??
Very easy nextPos = ( currentPos + currentDataSize + nextDataSize ) % nextDataSize

i will not get next datasize, because i used unions. only one data will get at one time..

ambarisha.kn 15 Junior Poster in Training

In the following code, we will get the output, and the data stores as follows.
actually i am getting dynamic input data..
first char is stored at 0th position
second long is stored at 1st position, because size of char is 1
third short is store at 5th position, because size of long is 4.

Actually what i want is
i have to leave 3 spaces after oth position, have to strore at 4th position
i have to leave 1 space after 5th position, have to store at 6th position


i.e
for long & float:
I have to store at 0,4,8,12,16...............

For short
I have to store at 0,2,4,6,8............

for double
i have to store at 0,8,16,24.........

for char
i have to store at 0,1,2,3,4,.........

How to change the code to get the output in the above indexes.......??

char *constDataArea;
data.Short=5;
data.Long= 6;
data.Char=1;

const size_t BUFSIZE = 1048576;
size_t datasize=0, nextpos=0, freepos=0;
constDataArea=(char *)malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Char);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Char, datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Long);
nextpos = freepos + datasize;					
memcpy(constDataArea+freepos,(char *)&data.Long,datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}						 
						
datasize=sizeof(data.Short);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Short, datasize);
freepos=nextpos;
								
printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[1], constDataArea[5]);

i have changed some corrections in the above code. is the following programming is good or please suggest me some other good idea.

char *constDataArea;
data.Short=5; …
ambarisha.kn 15 Junior Poster in Training

In the following code, we will get the output, and the data stores as follows.
actually i am getting dynamic input data..
first char is stored at 0th position
second long is stored at 1st position, because size of char is 1
third short is store at 5th position, because size of long is 4.

Actually what i want is
i have to leave 3 spaces after oth position, have to strore at 4th position
i have to leave 1 space after 5th position, have to store at 6th position


i.e
for long & float:
I have to store at 0,4,8,12,16...............

For short
I have to store at 0,2,4,6,8............

for double
i have to store at 0,8,16,24.........

for char
i have to store at 0,1,2,3,4,.........

How to change the code to get the output in the above indexes.......??

char *constDataArea;
data.Short=5;
data.Long= 6;
data.Char=1;

const size_t BUFSIZE = 1048576;
size_t datasize=0, nextpos=0, freepos=0;
constDataArea=(char *)malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Char);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Char, datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Long);
nextpos = freepos + datasize;					
memcpy(constDataArea+freepos,(char *)&data.Long,datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}						 
						
datasize=sizeof(data.Short);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Short, datasize);
freepos=nextpos;
								
printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[1], constDataArea[5]);
ambarisha.kn 15 Junior Poster in Training

Expected o/p is 1 5 6. but i am getting 1 0 0.. what is the corrections to get the expected o/p???

char *constDataArea;
data.Bool=1;
data.Short=5;
data.Long= 6;


const size_t BUFSIZE = 1048576;
size_t datasize=0, nextpos=0, freepos=0;
constDataArea=(char *)malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Bool);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Bool, datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Short);
nextpos = freepos + datasize;					
memcpy(constDataArea+freepos,(char *)&data.Short,datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}						 
						
datasize=sizeof(data.Long);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Long, datasize);
freepos=nextpos;
								
printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[1], constDataArea[2]);

This code is correct. we will get expected o/p. but the printf of last statement is wrong.
so we have to replace that printf as follows.

printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[4], constDataArea[6]);

because bool is of type int, so it takes 4 bytes. the next elemet will store from constDataArea[4] and again Short variable is of type short(2 bytes). so the next element will start from constDataArea[6].

ambarisha.kn 15 Junior Poster in Training

Expected o/p is 1 5 6. but i am getting 1 0 0.. what is the corrections to get the expected o/p???

char *constDataArea;
data.Bool=1;
data.Short=5;
data.Long= 6;


const size_t BUFSIZE = 1048576;
size_t datasize=0, nextpos=0, freepos=0;
constDataArea=(char *)malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Bool);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Bool, datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}
datasize=sizeof(data.Short);
nextpos = freepos + datasize;					
memcpy(constDataArea+freepos,(char *)&data.Short,datasize);
freepos=nextpos;
	
if (nextpos > BUFSIZE)
{  
printf("Out of memory\n");
exit(0);
}						 
						
datasize=sizeof(data.Long);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,(char *)&data.Long, datasize);
freepos=nextpos;
								
printf("const area:%d\t%d\t%d\t",constDataArea[0], constDataArea[1], constDataArea[2]);
ambarisha.kn 15 Junior Poster in Training

i implemented the above said logic in my program. its giving 3 errors. i have mentioned errors below the code

const size_t BUFSIZE = 1048576;
size_t datasize, nextpos, freepos=0;
char *constDataArea=malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
	printf("OUT of memory\n");
	exit(0);				
}
datasize=sizeof(data.Short);
nextpos = freepos + datasize;
memcpy(constDataArea+freepos,data.Short,datasize);
freepos=nextpos;
if (nextpos > BUFSIZE)
{  
	printf("OUT of memory\n");
	exit(0);				
}
datasize=sizeof(data.Double);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos,data.Double, datasize);
freepos=nextpos;

Errors:
1)Line 3: error c2440: 'intialising' :from void * to char * is not possible to change
2)Line 11: error c2664 : 'memcpy' : from short to const void * change is not possible
3)Line 20: error c2664 : 'memcpy' : from double to const void * change is not possible

ambarisha.kn 15 Junior Poster in Training

Thanks for reply. i will check this..
thank u very much

ambarisha.kn 15 Junior Poster in Training

hi,

i have some data in variables of different types.(short, int, long, float, char, double). now i have to create one pointer, have to allocate 1mb memory and have to store one by one in that pointer. How to do this.. plz give some clues to start..

which type i have to create a pointer..

ambarisha.kn 15 Junior Poster in Training

I am reading 4 bytes in binary file and stored in some variable named as *tmpbuf.
i am printing this variable in decimal value like this.
printf("%d",*tmpbuf);

But now what to do is i want to split 4 bytes into two and want to read those separately and saved in another variable. How to do this?

Ex:*tmpbuf=01 00 00 04; decimal value=16777220

Required o/p:
*tmpbuf1=01 00; decimal value=256
*tmpbuf2=00 04 decimal value=4

ambarisha.kn 15 Junior Poster in Training

The following is giving output as follows
String:Astro.cfg
Fail

If buff is Astro.cfg, it has to give success output, but it is giving fail. I want to print Success.. Please guide me regarding this pointer usage..

#include<iostream>
using namespace std;

int main()
{
	char arr[]="Asto.cfg";
	char *buff=&arr[0];
	printf("String:%s",buff);

	if(buff=="Asto.cfg")
	{
		cout<<"Success";

	}
	else 
		cout<<"Fail!!!!";
	cin.get();
}
ambarisha.kn 15 Junior Poster in Training

The above code won't compile. What is 'elem' ? a bool?
And you missed a semicolon after cin.get()

For other people who want to help: Here's the code from the header (it was discussed in another thread)

#include <iostream>
using namespace std;

template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
    typename T::const_iterator pos;

    std::cout << optcstr;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}

But to solve your problem:
You have to resize the output vector before you put values in it. So put this: vout.resize(vin1.size()); Right before the transform line.

thanks i have put vout.resize(vin1.size()); before transform line. now the code is working fine.

ambarisha.kn 15 Junior Poster in Training

The following program is giving error as follows. please get me the solution how to debug this error.
Error:
Debug Assertion Failed!

Program: ...
File: d:\program files\microsoft visual studio 8\vc\include\vector
Line: 1556

Expression: ("this->_Mycont != NULL && this->_Myptr != NULL", 0)

#include<iostream>
#include<vector>
#include<deque>
#include<list>
#include<algorithm>
#include<functional>
#include "print.hpp"
int main()
{
	vector<bool> vin1;
	vector<bool> vin2;
	vector<bool> vout;

	cout<<"Enter the value of vin1 in binary\n";
	for(int i=1;i<=8;++i)
	{
		cin>>elem;
		vin1.push_back(elem);
	}
	cout<<"\nEnter the value of vin2 in binary\n";
	for(int i=1;i<=8;++i)
	{
		cin>>elem;
		vin2.push_back(elem);
	}
                PRINT_ELEMENTS(vin1,"vin1:      ");	
	PRINT_ELEMENTS(vin2,"vin2:      ");					transform(vin1.begin(), vin1.end(),         //Error
				vin2.begin(), vout.begin(),
				logical_and<bool>());
	PRINT_ELEMENTS(vout,"vin1 & vin2: ");
cin.get()
}
ambarisha.kn 15 Junior Poster in Training

I wrote the code for Arithmetic, relational and binary operations. Here i have intilaised all inputs. I want to give inputs from keyboard instead of intialisation or direct Push_back from loop. How to do this? Please check the following code and please help me to give inputs from keyboard.

#include<iostream>
#include<vector>
#include<deque>
#include<list>
#include<algorithm>
#include<functional>
#include "print.hpp"
using namespace std;
int main()
{
	vector<int> V1;  //vector container for integer elements
	deque<int> V2;  //dequeu container for integer elements
	list<int> V3;      //list container for integer elements
	list<float>V4;   //list container for float elements		

	deque<int>::iterator pos;		// declaration of iterator	

	//initialisation of binary values
	bool a[8]={1,0,1,0,1,0,1,0};
	bool b[8]={1,1,1,1,1,1,1,1};
	
	//vector container for boolean elements
	vector<bool> va(a, a + 8);   
	vector<bool> vb(b, b + 8);
	vector<bool> vc(8);

		
	
	//append elements from 12 to 18 in Vector container V1
	for(int i=12;i<=18;++i)
	{
		  V1.push_back(i); 	//inserts an element at the back of the collection
	}

		
	//append elements from 2 to 8 in deque container V2
	for(int i=2;i<=8;++i)
	{
		  V2.push_front(i);	//inserts an element at the front of the collection
	}
	
	
	char ch;
	do
	{
	cout<<"\nSelect any one peration\n1.Add (V1+V2)\n2.Subtract (V1-V2)\n3.Multiplication (V1*5)\n4.Division(V2/5)\n5.Equal_to\n6.Greater\n7.Less_equal\n8.Logical operations"<<endl;
	cin>>ch;
	switch(ch)
	{
	case '1': 
                          //transform  resulted element to list V3 after addition of each element in                       //vector V1 and deque V2
			 // - Add transformed values
	transform(V1.begin(), V1.end(),	//First sorce range
				V2.begin(),	//Second source range
				back_inserter(V3),		//destination 
				plus<int>());	//operation	
			
	PRINT_ELEMENTS(V1,"V1:    ");		//display the elements of V1
	PRINT_ELEMENTS(V2,"V2:    ");		//display the elements of V2
	PRINT_ELEMENTS(V3,"V1+V2: ");	//dispaly the resulted output
	V3.clear();
	cout<<endl<<endl;
	break;
	case '2': 
	//transform  resulted element …
ambarisha.kn 15 Junior Poster in Training

> But the following code is not working.c
Did you include the code for compose2? It's not a standard STL function, but Edward would guess that you mean to use the one defined in Nicolai Josuttis' STL book:

#include <functional>

/* class for the compose_f_gx_hx adapter
 */
template <class OP1, class OP2, class OP3>
class compose_f_gx_hx_t
 : public std::unary_function<typename OP2::argument_type,
                              typename OP1::result_type>
{
  private:
    OP1 op1;    // process: op1(op2(x),op3(x))
    OP2 op2;
    OP3 op3;
  public:
    // constructor
    compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3)
     : op1(o1), op2(o2), op3(o3) {
    }

    // function call
    typename OP1::result_type
    operator()(const typename OP2::argument_type& x) const {
        return op1(op2(x),op3(x));
    }
};

/* convenience function for the compose_f_gx_hx adapter
 */
template <class OP1, class OP2, class OP3>
inline compose_f_gx_hx_t<OP1,OP2,OP3>
compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) {
    return compose_f_gx_hx_t<OP1,OP2,OP3>(o1,o2,o3);
}
// remove all elements that are greater than four and less than seven
// - retain new end
vector<int>::iterator pos;
pos = remove_if (coll.begin(),coll.end(),
                 compose_f_gx_hx(logical_and<bool>(),
                                 bind2nd(greater<int>(),4),
                                 bind2nd(less<int>(),7)));

// remove ``removed'' elements in coll
coll.erase(pos,coll.end());

I think this code is too complicated. I want to do logic operations by using simple algorithms. Is there any simple methods to show logical opertaions ie logical_and, logical_or and logical_not

ambarisha.kn 15 Junior Poster in Training

i want to write code by using any of the algorithm not using array subscript. What is compose2 algorithm. What is the syntax for this? i want to use like this. But the following code is not working.could any one plz tell me errors in this.

vector<int>::iterator pos;
       pos = remove_if (coll.begin(),coll.end(),
                           compose2(logical_and<bool>(),
                                           bind2nd(greater<int>(),4),
                                           bind2nd(less<int>(),7)));


       //remove "removed" elements in coll
       coll.erase(pos,coll.end());