Solved

struct to char

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

761 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