Solved

struct to char

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

631 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