kushalkoolwal
10-19-2004, 06:53 AM
hi,
I have a problem while I am storing the values in the follwoing structure. I have want to store the value 8 in code char data type, 1234 in offset array and test in filename array.
Now after stroing the values in all the 3 variables, whenever I try to print the value of offset it shows me the value stored in offset and also in the filename. In short it appends both the values. For example when I try to print p1.offset it gives me 1234test instead of 1234.
struct req_block
{
char code;
char offset[4];
char filename[4];
};
struct req_block p1;
void main()
{
p1.code=8;
strcpy(p1.offset,"4563");
strcpy(p1.filename="test");
printf("\n%d \n%s \n%s",p1.code,p1.offset,p1.filename);
}
Kindly tell me where I have gone wrong? is there any better way of storing these values in the structure instead of using strcpy. Also when I try to give statement like
p1.offset="1234" it gives me an error. why is it so?
thanks
Kushal
I have a problem while I am storing the values in the follwoing structure. I have want to store the value 8 in code char data type, 1234 in offset array and test in filename array.
Now after stroing the values in all the 3 variables, whenever I try to print the value of offset it shows me the value stored in offset and also in the filename. In short it appends both the values. For example when I try to print p1.offset it gives me 1234test instead of 1234.
struct req_block
{
char code;
char offset[4];
char filename[4];
};
struct req_block p1;
void main()
{
p1.code=8;
strcpy(p1.offset,"4563");
strcpy(p1.filename="test");
printf("\n%d \n%s \n%s",p1.code,p1.offset,p1.filename);
}
Kindly tell me where I have gone wrong? is there any better way of storing these values in the structure instead of using strcpy. Also when I try to give statement like
p1.offset="1234" it gives me an error. why is it so?
thanks
Kushal