I'm not familiar to pointers and I stumbled upon segmentation fault on my code, wheres if I don't use pointers this code runs perfectly.
#include <stdio.h>
#include <string.h>
int main()
{
char *string[100],i,j;
char *(*odd)[100];
i = j = 0;
fgets(*string, 100, stdin);
while (*string[i] != '\0') {
if (i % 2 == 0) {
*odd[j++] = string[i];
}
i++;
}
*odd[j] = '\0';
printf("Characters at odd position: %s\n",*odd[j]);
return 0;
}
I'm guessing that I'm printing the odd array the wrong way, but I can't print it just using *odd as well.
*string[strlen(*string) - 1] = '\0';do?stringsupposed to be a single string, or an array of strings? Right now it's the latter, an array of strings. Continue from there.*string[strlen(*string) - 1] = '\0';this line is a little bit strange => you want to be sure to have null character at the end of string (ie you don't be sure that you have one) and for that you usestrlenwhich look for a null character....*odd[j] = '\0';is important! you have to put null character at the end of odd string