Thread: write value from char * to char[] ?

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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, 12:36 PM
  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