Solved

struct to char

Posted on 2001-07-22
5
636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 100
List out all word 7 358
if loop in java 3 174
Trying to run powershell  in a batch file. How do I do this? 8 124
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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