CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2001
    Posts
    24

    Assigna string to a char buffer[]

    I have the following code

    char buffer [100];
    struct sendMsg {
    char func_id[20];
    int data;
    } send_msg;

    ....
    ...

    int paramsignal=12;
    sprintf(buffer,"%s 0 0 0 0 %d", "Sin", paramsignal);



    How can I assign the containing of the struct member send_msg.func_id to be located in the buffer placed in the sprintf instead of the string "Sin"?
    I have to use the sprintf function in my source code application.

    Is this correct
    sprintf(buffer,"%s 0 0 0 0 %d",send_msg.func_id, paramsignal);


  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Assigna string to a char buffer[]

    yes, it is correct


    The best things come to those who rate

  3. #3
    Join Date
    Aug 1999
    Posts
    427

    Re: Assigna string to a char buffer[]

    Yes it is correct.
    Do your have a problem with it ?
    If so post some code


  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Assigna string to a char buffer[]

    It's fine as long as func_id is a null-terminated string.

    He who breaks a thing to find out what it is, has left the path of wisdom - Gandalf
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured