Thread: simple char** practice

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243

    simple char** practice

    im just wondering if im using a 'char**' (and dynamic memory) properly, if you could let me know. ie, missing another set of []'s or a * or & somewhere.
    Code:
    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        
        char* test= "hello there";
        
        char** temp = (char**) malloc(sizeof(char**) * 1);
    
        temp[0] = (char*) malloc(sizeof(char*)* 20);
        
        strcpy(temp[0],test);
        printf("'&#37;s'\n",temp[0]);
        
        free(temp[0]);
        free(temp);
        
        getchar();
    }
    i know this program isnt useful, im just wondering if it is correct.
    thanks
    Last edited by nadroj; 04-12-2007 at 10:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM