title: Trying to printf a char in a specific index in a char Array
body: <p>The program works i allocate and reallocate data properly.</p>
  
  <p>I wanted to break if c== -1, so i tried to compare c to "-" and  data[i-1] == '1' but i got an error. So i tried to just print it to see what comes up.</p>
  
  <pre><code>   for (i=0;;i++) {
          c=getchar(); /* put input character into c */
          if (c== '1'  ) {               // need to find a way to change it to -1
              printf("n-1 is %c",data[i]); // ask
              break;
              //&amp;&amp; (data[i-1] == '-')
          }
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>n-1 is ?
  </code></pre>
  
  <p>*The ? is upside down</p>
  
  <p>Any ideas. Thank you.</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>char *getInput()
  {
  
      char *data,*temp;
      data= malloc(sizeof(char));
      char c; /* c is the current character */
      int i; /* i is the counter */
      printf ("\n Enter chars and to finish push new line:\n");
      for (i=0;;i++) {
          c=getchar(); /* put input character into c */
          if (c== '1'  ) {               // need to find a way to change it to -1
              printf("n-1 is %c",data[i]); // ask
              break;
              //&amp;&amp; (data[i-1] == '-')
          }
          data[i]=c; /* put the character into the data array */
          temp= realloc(data,(i+1)*sizeof(char)); /* give the pointer some memory */
          if ( temp != NULL ) {
              data=temp;
          } else {
              free(data);
              printf("Error allocating memory!\n");
              return 0 ;
          }
      }
  </code></pre>