title: is it possible to set the value of allocated memory with loops?
body: <p>I want to manually set each individual character for my pointer instead of typing out the string/having another array and then simply copying the values.  This is homework, but I have it finished.</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  /*function declarations */
  
  void assignAlpha(char *pointer);
  void assignNumeric(char *pointer);
  
  int main()
  {
      char  *cp;
      assignAlpha(cp);
      assignNumeric(cp);
  
  }
  
  void assignAlpha(char *pointer)
  {
      /* allocate space for a-z character string */
      pointer = malloc(26*sizeof(char));
  
      char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
      strcpy(pointer, alphabet);
  
      /*print the values*/
      printf("%s\n", pointer);
  
      /*free the memory allocated */
      free(pointer);
  }
  
  void assignNumeric(char *pointer)
  {
      /* allocate space for the 0-9 character string*/
      pointer = malloc(10*sizeof(char));
  
      /* input values */
      char alphaArray[10];
      int currentChar = 30;
      int i;
      for(i = 0; i &lt;10; i++)
      {
          alphaArray[i] = i + '0';
          currentChar++; 
      }
      /* copy string to pointer */
      strcpy(pointer, alphaArray);    
      /* print out the results */
      printf("%s\n", pointer);
      /* free the memory allocated */
      free(pointer);
  }
  </code></pre>
  
  <p>What I have tried doing, but it seems to fail:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  /*function declarations */
  
  void assignAlpha(char *pointer);
  void assignNumeric(char *pointer);
  
  int main()
  {
      char  *cp;
      assignAlpha(cp);
      assignNumeric(cp);
  
  }
  
  void assignAlpha(char *pointer)
  {
      /* allocate space for a-z character string */
      pointer = malloc(26*sizeof(char));
  
      int i;
      for (i=0; i &lt; 26; i++)
      {
          pointer = i + 'a';
          pointer++;
      }
  
      /*print the values*/
      printf("%s\n", pointer);
  
      /*free the memory allocated */
      free(pointer);
  }
  </code></pre>
  
  <p>I thought that if I go through each memmory address that I have allocated and set the value to the next character it would work, but I apparently was wrong.  Like I said this was a homework assignment, but I could hand in what I have that works and be fine. Any guidance on how to do this (if its possible) would be appericated!</p>
  
  <p>Edit: I get the following error compiling "Assignment makes pointer from integer without a cast" </p>