Click here to Skip to main content
15,503,315 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    int main(){
         int n,i,j=0;
         char** a = (char**)calloc(n,sizeof(char*));
         printf("enter the level of pyramid: ");
         scanf("%d",&n);
         for(i=0;i<n;i++){
            *(a+i)=(char*)calloc((2*n-1),sizeof(char));
            while(j<(n-1-i)){
                 *(*(a+i)+j) = ' ';
                 j++;
            }
             while(j<(n-1-i+(2*i+1))){
                 *(*(a+i)+j)='*';
                j++;
            }
            while(j<(2*n-1)){
                *(*(a+i)+j) = ' ';
                 j++;
            }
             //printf("%s",*(a+i));
            puts(*(a+i));
        }
         return 0;
     }


What I have tried:

Please refer description, I am unable to debug the code
Posted
Updated 5-Oct-21 23:29pm
v3
Comments
jeron1 5-Oct-21 17:56pm    
and the error would be?
ABDEALI ATTARWALA 6-Oct-21 0:51am    
the output for n=3 is displayed as follows
*
and for every n it is just printing one star and leaving spaces, if possible please run the code so that you can see the complete output
Thank you

Quote:
I have written star pyramid pattern code using pointer to pointer in C but can't resolve the error

On first look, I would start by resetting the column number on every line.
C++
for(i=0;i<n;i++){
   *(a+i)=(char*)calloc((2*n-1),sizeof(char));
   j=0;
   while(j<(n-1-i)){
 
Share this answer
 
Comments
ABDEALI ATTARWALA 6-Oct-21 0:58am    
Thank you sir, it really worked!
Learn to use the debugger for debugging and understand the code. Start with some Debugger video tutorial.

When you dont like debugging than coding is pain in the ass ;-)
 
Share this answer
 
Comments
ABDEALI ATTARWALA 7-Oct-21 7:03am    
thanks, I'll surely look into it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900