I'm making a function that searches through a sentence to find a letter. Right now, I'm having trouble initializing a dynamic array for the user's sentence.
char * get_info(char *ch) {
char *str;
int i = 0;
printf("Enter a sentence to seach: ");
while ((str[i++] = getchar()) != '\n');
str[i] = '\0';
printf("Enter a character to search for: ");
*ch = getchar();
return str;
}
The problem lies when I call str[i++]. Nothing I've tried or looked has helped so far. Any suggestions? Thanks!
getline.