write value from char * to char[] ?

This is a discussion on write value from char * to char[] ? within the C++ Programming forums, part of the General Programming Boards category; hi, i have this: Code: BOOL function(const char *Text) { // func } but i need to cut text from ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    8

    Post write value from char * to char[] ?

    hi, i have this:

    Code:
    BOOL function(const char *Text)
    {
        // func
    }
    but i need to cut text from one character occurance to the end like this:
    Code:
                    char txt[32];
    		
    		if ((ptr = strstr(txt, ":")) != 0)
    			*ptr = '\0';
    so i wanted to make txt = Text and do operations above but i can't =\

    would appreciate any help ^^

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    First you need to use strcpy() to copy from text to txt
    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.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    8
    wow it works thx, sry i tried it and it was giving errors wtf =\

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    You can't assign directly to an array. For strings (char), you need to use strcpy. For other things, it's usually memcpy. Or in C++, we tend to use C++ constructs such as std::vector which allows us to copy stuff merely be assigning one object to another.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The UNIX System Interface
    By rrc55 in forum C Programming
    Replies: 1
    Last Post: 10-20-2009, 05:56 PM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM

Tags for this Thread


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