Thread: Is this correct???way of doing??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    Is this correct???way of doing??

    Hello,

    Please anybody here can explain me whether i am doing this correctly or not?i want to create 2 dimesional array of strings with double pointer. Here is the code kindly explain am i doing it fine or is there any mistake in it?


    Code:
    #include <stdio.h>
    #include <string.h>
    #include <alloc.h>
    
    int main(void)
    {
    char **a,i;
    clrscr();
    
    a=(char** )malloc(sizeof(char)*10);
    
    for(i=0;i<10;i++)
    {
    	a[i]=(char* )malloc(sizeof(char)*4);
    	strcpy(a[i],"abc");
    	printf("&#37;s\n",a[i]);
    }
    getch();
    return 0;
    }
    Last edited by chottachatri; 02-11-2008 at 04:18 AM.

Popular pages Recent additions subscribe to a feed