Can anyone please help me with my confused idea of pointers to pointers. I need to write code to input a poem from a user and output the poem backwards(line by line). I made a fairly pathetic attempt but can anyone tell me what im doing wrong!!!!!!
P.S: I also need to use malloc and realloc
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int getline(char line[],int max)
main()
{
int nch = 0;
int c;
max = max - 1;
while((c = getchar*()) !=EOF)
{
if(c=='\n')
break;
if(nch<max)
{
line[nch] = c;
nch = nch + 1;
}
}
if(c==EOF&& nch ==0)
return EOF;
line[nch] = '\0';
return nch;
}
{
char *temp_line_ptr;
char *line_ptr;
char **poem_ptr;
char **temp_poem_ptr;
printf("Enter a line of a poem\n",nch);
char *temp_line_ptr = nch;
len = malloc(strlen(*temp_line_ptr)+1);
strcpy(line_ptr,temp_line_ptr);
line_ptr = malloc(sizeof(CHAR)*len);
if(line_ptr == NULL)
{
printf("out of memory\n");
return
}
poem_ptr = malloc(sizeof(char*))
*poem_ptr = line_ptr;
while(getline(line,CHAR) != EOF)
{
*line_ptr = &temp_line_ptr;
**temp_poem_ptr = &poem_ptr;
}
temp_poem_ptr = realloc(poem_ptr,sizeof(char*));
if(temp_poem_ptr !=NULL)
{
line_ptr = temp_poem _ptr;
}
else
{
printf("out of memory\n");
}
else
{
poem_ptr = temp_poem_ptr;
}
*poem_ptr = line_ptr;
printf("\n,line_ptr)
free(line_ptr)
line_ptr = NULL;
}