1
I’m trying to make a code that only prints the third to a typed string, but my program is endless, how to recognize the given enter for the program to end?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char **texto= NULL;
int i=0,j;
char letra;
do{
texto=(char**) realloc(texto, (i+1)*sizeof(char*));
do{ texto[i]= NULL;
j=0;
letra=getchar();
texto[i]=(char*)realloc(texto[i], (j+1)*sizeof(char));
texto[i][j]=letra;
if ((i+1)%3==0){
printf("%c", letra);
}
j++;
}while(letra!=' ');
i++;
printf("%d", (int)letra);
}while ((int)letra!=10);
free(texto);
return 0;
}
Good night! I had taken a base code and adapted it to my needs, had pointer usage requirements and dynamic allocation, got a little lost in it. But thanks for the help, what do I need to focus on to master this part? I could turn the variable letter to integer and use the characters of the ASCII table instead of ' n'?
– Frybii
First master simple logic. Second take something to use pointers in a way that is how you really use it, keep doing this lot of relocations only works in exercise
– Maniero