noob question

This is a discussion on noob question within the C++ Programming forums, part of the General Programming Boards category; Hi.. Am I allowed to do: Code: char *buffer = new char[128]; sprintf(buffer, "some text here.."); unsigned int textlen = ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    noob question

    Hi..
    Am I allowed to do:

    Code:
    char *buffer = new char[128];
    sprintf(buffer, "some text here..");
    unsigned int textlen = strlen(buffer);
    
    recv(socket, buffer + textlen, 128 - textlen , 0);
    and I get in buffer "some text here..<received buffer here>" ?

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    why do you post this in the C++ forum? It's C code.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by Ideswa
    why do you post this in the C++ forum? It's C code.
    Well if he posted on the C board, he'd probably be told to post on the C++ board...

    The new keyword has no place in C.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    > It's C code.
    It's a horrid mix of both - check the new call.

    > and I get in buffer "some text here..<received buffer here>" ?
    Yes, so long as you solve all the other problems of
    - checking the return result
    - not allowing space to store a \0 to make it once again a C-string
    - not allowing for fragmented messages
    + some other stuff as well
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 09:28 PM
  2. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 01:28 PM
  3. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  4. Very noob question :(.
    By GamerProduction in forum Tech Board
    Replies: 4
    Last Post: 04-14-2007, 06:40 AM
  5. Noob question ( little dos program )
    By Demon1s in forum C++ Programming
    Replies: 13
    Last Post: 04-04-2003, 09:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21