Guest User

Untitled

a guest
Apr 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define BUFFERSIZE 1024
  5. //
  6. void sample(void)
  7. {
  8. // size_t is unsigned int type.
  9. size_t str_size = 0, i = 0;
  10. int alphabet = 0;
  11. // string: char array
  12. // You should initialize them for safety.
  13. char word[BUFFERSIZE] = "", wordindex[BUFFERSIZE] = "";
  14. // You may need a buffer.
  15. char buffer[BUFFERSIZE] = "";
  16. printf("Enter your desired word or sentence: ");
  17. // string word, its name is a pointer.
  18. //scanf("%s", word);
  19. // get a string for a line.
  20. gets(word);
  21. // let strlen return size_t type.
  22. str_size = strlen(word);
  23. for (i = 0; i < str_size; i ++)
  24. {
  25. alphabet = (int)word[i];
  26. itoa( alphabet, buffer, 2);
  27. strcat( wordindex, buffer);
  28. }
  29. // print binary string.
  30. printf("%s\n", wordindex);
  31. }
  32. void main(void)
  33. {
  34. sample();
  35. system("PAUSE");
  36. }
Add Comment
Please, Sign In to add comment