Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

struct to char

Posted on 2001-07-22
5
Medium Priority
?
656 Views
Last Modified: 2013-11-20
i am new to mfc's & vc++ .
1.i want to copy a structure of 516 bytes consisting of various data types(fields) into a character string .
2.an other problem is copying struct into
MS-Access  directly .
is there a way we can do it in c,c++
or mfc's can be used
0
Comment
Question by:rammohan_77
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
gilad_no earned 150 total points
ID: 6307405
I am not sure if I understood you. Do you want to copy all the structure as a single string ? If so, you can use memcpy.

struct myStruct {
 ...
 ...
} sTmp;

char szString[sizeof(myStruct)+1]={0}; // You must add a zero to terminate the string
memcpy(szString,&sTmp,sizeof(myStruct));

If you want to insert it to access, you need to use DB functions. Check the ODBC documentation.
0
 

Expert Comment

by:ahmadrazakhan
ID: 6307794
do not cpy structure to string, use byte array instead. caz if some  string is member of structure, u will b in trouble.
0
 

Expert Comment

by:ahmadrazakhan
ID: 6307796
do not copy structure to string, use byte array instead. caz if some  string is member of structure, u will b in trouble.
0
 

Author Comment

by:rammohan_77
ID: 6358481
hi qilad no,

i am able to get a string from the structure but the value is different bcaz, it takes the ascii value of whole string and displays a single character.but i want view individual structure values in the string how is it possible.
0
 

Expert Comment

by:gilad_no
ID: 6591390
Does your structure has multiply members ?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question