store data in a struct

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TYF
    New Member
    • Nov 2007
    • 11

    store data in a struct

    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
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    Originally posted by TYF
    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.


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

    Regards

    Comment

    • TYF
      New Member
      • Nov 2007
      • 11

      #3
      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!

      Comment

      • TYF
        New Member
        • Nov 2007
        • 11

        #4
        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.

        Comment

        • oler1s
          Recognized Expert Contributor
          • Aug 2007
          • 671

          #5
          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.

          Comment

          • mostafa110
            New Member
            • Oct 2007
            • 6

            #6
            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,3 0);
            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

            Comment

            • oler1s
              Recognized Expert Contributor
              • Aug 2007
              • 671

              #7
              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.

              Comment

              • TYF
                New Member
                • Nov 2007
                • 11

                #8
                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..

                Comment

                Working...