Solved

struct to char

Posted on 2001-07-22
5
623 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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Host to IP 7 73
Problem to event 3 49
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 84
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now