structure to file [REMAIN UNSOLVED] [CLOSED]
-
DavidCrow wrote:
You probably meant to use _tcscpy() here instead.
This works like a charm
_tcscpy(st.detail.Name,TEXT("Williams"));
_tcscpy(st.detail.Address,TEXT("B-33 Lane 5"));But another problem arises cannot set values in long and DWORD variables
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};struct Student{
Detail detail;
DWORD code;
};Student st;
st.code = 1;but st.code stores a default value of -16843010 and same problem with long data type st.Details.Age = 25 stores 65278, instead of 25.
:confused: :wtf: MODIFIED: _tcscpy_s() now works. i was making a small mistake. Now it works.._tcscpy_s(st.detail.Name,_tcslen(st.detail.Name),TEXT("WILLIAMS"));
Some Day I Will Prove MySelf :: GOLD
modified on Wednesday, February 16, 2011 10:43 PM
goldenrose9 wrote:
i was making a small mistake.
And you still are.
_tcslen()
does not tell you the size/capacity ofName
, but rather how many characters it is currently holding."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
goldenrose9 wrote:
i was making a small mistake.
And you still are.
_tcslen()
does not tell you the size/capacity ofName
, but rather how many characters it is currently holding."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
yes you are right. but when i use
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
stack around
st
get corrupted. moreover when i initialize st withst.code =1;
st.detail.Age = 25;then the value is changed to
st.code = 4278124286
st.detail.Age = -16843010i had intialized the st as given
st.code =1;
st.detail.Age = 25;
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
_tcscpy_s(st.detail.Address,sizeof(st.detail.Address),TEXT("BB-33 LANE 5"));Some Day I Will Prove MySelf :: GOLD
-
yes you are right. but when i use
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
stack around
st
get corrupted. moreover when i initialize st withst.code =1;
st.detail.Age = 25;then the value is changed to
st.code = 4278124286
st.detail.Age = -16843010i had intialized the st as given
st.code =1;
st.detail.Age = 25;
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
_tcscpy_s(st.detail.Address,sizeof(st.detail.Address),TEXT("BB-33 LANE 5"));Some Day I Will Prove MySelf :: GOLD
Have you considered:
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));For clarities sake, you might consider renaming the
st
member ofStudent
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Have you considered:
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));For clarities sake, you might consider renaming the
st
member ofStudent
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
whenever
st.code
andst.st.Age
is initialized with any value the result is,st.code = 4278124286
st.detail.Age = -16843010Some Day I Will Prove MySelf :: GOLD
-
whenever
st.code
andst.st.Age
is initialized with any value the result is,st.code = 4278124286
st.detail.Age = -16843010Some Day I Will Prove MySelf :: GOLD
You need to look more closely at the code snippet I provided. You should not be assigning or referencing
st.Detail
. In yourStudent
structure,Detail
is a type of structure, not an instance of one."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
You need to look more closely at the code snippet I provided. You should not be assigning or referencing
st.Detail
. In yourStudent
structure,Detail
is a type of structure, not an instance of one."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
please give a small example. :confused:
Some Day I Will Prove MySelf :: GOLD
-
please give a small example. :confused:
Some Day I Will Prove MySelf :: GOLD
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
on using
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));following error occurs.
Error 1 error C2039: 'st' : is not a member of 'Student'
Error 2 error C2228: left of '.Age' must have class/struct/unionSome Day I Will Prove MySelf :: GOLD
-
on using
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));following error occurs.
Error 1 error C2039: 'st' : is not a member of 'Student'
Error 2 error C2228: left of '.Age' must have class/struct/unionSome Day I Will Prove MySelf :: GOLD
I just compiled your code with my changes. It compiled and ran fine.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
I just compiled your code with my changes. It compiled and ran fine.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
please give a sample so that i can understand my mistake.
Some Day I Will Prove MySelf :: GOLD