SHARE
TWEET

Untitled

a guest Jan 12th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char string[30];
  2. // Set the array to the lowercase alphabet using the way we already
  3. // know: brackets
  4. for (int i = 0; i < 26; i++)
  5. {
  6. // Character constants can be treated like integers. It saves us from
  7. // having to look up to see what integer value the lowercase letter
  8. // A has.
  9. string[i] = 'a' + i;
  10. }
  11. string[26] = 0;
  12. printf("%s\n",string);
  13. // Here's another way: using pointers and some math
  14. for (int i = 0; i < 26; i++)
  15. {
  16. char *index = string + (i * sizeof(char));
  17. // Use a capital A just for something different
  18. *index = 'A' + i;
  19. }
  20. string[26] = 0;
  21. printf("%s\n",string);
RAW Paste Data
Top