468,457 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

store data in a struct

11
hello, im completely new to c and programming.

now i need to store data from a input buffer in a struct and then sending the struct back, not the buffer, but i dont know how to start.any help would be nice. thx
Nov 16 '07 #1
7 3776
Meetee
931 Expert Mod 512MB
hello, im completely new to c and programming.

now i need to store data from a input buffer in a struct and then sending the struct back, not the buffer, but i dont know how to start.any help would be nice. thx
Refer the following link. It will give you an idea about how to store data in buffer.
http://faq.cprogramming.com/cgi-bin/...wer=1044873249

You can store this data from buffer to struct variable. To know more search google for "struct in C"

Regards
Nov 16 '07 #2
TYF
11
thx zodilla58, i read all this, but its not exactly what im looking for and i also know most of them already. i should be more specific, but how when i have absolutely no clue what to do!! damn, thanks god its w-end!
Nov 16 '07 #3
TYF
11
too bad, im still on the office working on this.

new question. is there any way to get the size of, or indexing a void type buffer?
for now, i malloced some space and put all the data in this temp buffer to work with, but i guess there is some better ways to do this.
Nov 16 '07 #4
oler1s
671 Expert 512MB
now i need to store data from a input buffer in a struct
Then this struct better have a buffer within it big enough to store the data from the input buffer.

then sending the struct back
Which shipping company are you using to send the struct back? I hear UPS is really bad, but FedEx is quite good if not more expensive.

new question. is there any way to get the size of, or indexing a void type buffer?
Void is not a type so much as a lack of type. You canít declare something of type void. If you have a void pointer, you canít do any dereference operations, or get the size, as it is typeless.

or now, i malloced some space and put all the data in this temp buffer to work with
Well, you do have to allocate memory somehow, either on the stack or dynamically through malloc or whatever.

As far as I can understand, youíre just trying to copy the contents of one buffer into another. Itís a simple memory copy. We could assist you better, if you gave more details. You show no code. You donít use good terminology. We are left confused.
Nov 16 '07 #5
Dear,
Type below code:

typedef struct _EXAMPLE
{
int i;
int c;
}EXAMPLE;

EXAMPLE GetSum(int k1,int k2)
{
EXAMPLE ex;
ex.i=k1;
ex.c=k2;
return ex;
}

//CPP file
EXAMPLE exx;
exx=GetSum(20,30);
cout<<"i"<<exx.i;
cout<<"c"<<exx.c;

Output
i =20
c=30
if you declare your struct in header file YOU MUST ADD #include "myheader.h"
at the first of implementation file(CPP) in your project after #stdafx.h
Nov 17 '07 #6
oler1s
671 Expert 512MB
Mostafa, your code is nonsensical. You have not read the forum rules. And you haven't read the OP's question, in which he states he is using C.

I suggest you spend some time doing some reading: forum rules and your C and C++ books before you give out advice. You'll end up misleading the OP with ridiculous answers.
Nov 17 '07 #7
TYF
11
hello,
i wasnt able to work on at the w-end, sorry for not posting.im so sorry leaving you confused, im still confused too.i do and did alot of researching before bothering you guys posting on this forum.but i just didnt found the relevant infos.i didnt post any code cause of security and copyright reason.and i use wrong terminology and bad english cause english isnt my native language and i never learned something about programming at school.for me learning the syntax of c is easy but to understand what every thing is doing is another thing.
may programming isnt for everyone.

thx to mustafa for trying to help.however im not into c++ while i still dont get c.

i guess it isnt just simple memory copying, i will post some code examples..
Nov 19 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by forums_mp | last post: by
11 posts views Thread by mwebel | last post: by
13 posts views Thread by liujiaping | last post: by
2 posts views Thread by Laszlo Nagy | last post: by
3 posts views Thread by M.-A. Lemburg | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.