title: how to print a string from dynamically allocated arrays at a given position
body: <p>I want to use the function to print one string of a given position from keybord, in the exact order as they are in the array but changing the other chars to null. 
  The problem is that the first loop of the function won't even execute and I have no idea why. </p>
  
  <p>-ex: first output: </p>
  
  <pre><code>e il cie                       enta traspare   e
  </code></pre>
  
  <p>-and by passing to the function a=2, i want to get output like:</p>
  
  <pre><code>cie //and the rest of the chars must be '\0'
  
  
  char no_words(char *sentence, int a)
  {
    int count=0,i,len;
    char lastC;
    len=strlen(sentence);
  
    if(len &gt; 0)
    {
      lastC = sentence[0];
    }
    for(i=0; i&lt;=len; i++)
    {
      if((sentence[i]==' ' || sentence[i]=='\0') &amp;&amp; lastC != ' ')
      {
        count++;
      }
      lastC = sentence[i];
  
      if(a!=count-1){
        sentence[i] = '\0';
        printf("%c", sentence[i]);
      }else
        printf("%c", sentence[i]);
    }
    return 0;
  }
  </code></pre>
  
  <p>//function that divides my text </p>
  
  <pre><code>char fun(char *tab, char warunek){
  
  int i,l=0;
  l = strlen(tab);
  i=0;
  char poczatek;
  
  
  while(i&lt;l){
  
  
  do{
      if(tab[i] == '\n'){
          printf("\n");
      }
  
      if(*(tab+i) == warunek &amp;&amp; i&lt; l){
  
          do{
  
              printf("%c", *(tab+i));
              ++i;
  
          }while (*(tab+i) != warunek &amp;&amp; i &lt; l);
          printf("%c", *(tab+i));
  
      }
  
      *(tab+i) = '\0';
      printf("%c", *(tab+i));
      ++i;
  
  
  }while (*(tab+i) != warunek &amp;&amp; i &lt; l);
  
  
  }
  *(tab+l)= '\0';
  
  
  
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>//in main </p>
  
  <pre><code>int main(){
  
  char **array = NULL;
  int i,j;
  char line[100];  
  int line_count=0;
  int line_lenght=0;
  int a;
  char warunek;
  int l=0;
  int *lenght;
  char **arr2 =NULL;
  
  FILE *fp;
  fp = fopen("tekst1.txt", "r");
  if(fp == NULL){
      printf("blad otwarcia pliku!");
      exit -1;
  }
  
  while (fgets(line, sizeof(line),fp) != NULL){ 
      line_count++;
  }
  
  rewind(fp);
  
  
  array = malloc(sizeof(char*) * line_count); 
  if (array == NULL){
      return 0;
  }
  
  
  for (i=0; i&lt;line_count; i++){
  
      fgets(line, sizeof(line), fp); //szczytuje po 1 linii
  
      line_lenght = strlen(line);
  
  
      array[i] = malloc(line_lenght +1); //+1 for null
  
  
      strcpy(array[i], line);
  
  }
  
  for (i=0; i&lt;line_count; i++){
      printf("%s", array[i]);
  }
  
  printf("\nenter position\n");
  scanf(" %d", &amp;a);
  printf("\nenter condition\n");
  scanf(" %c", &amp;warunek);
  printf("\n\n");
  
  
  
  
  
  for (j=0; j&lt;line_count; j++){
  
          *(*(array)+j) = fun(*(array+j) , warunek);
  
  }
  
  
  
  for (j=0; j&lt;line_count; j++){
  
      *(*(array)+j)=print_nth_word(*(array+j),a);
      printf("\n");
  
  }
  
  
  
   return 0;
  </code></pre>
  
  <p>}</p>