Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define BUFFERSIZE 1024
- //
- void sample(void)
- {
- // size_t is unsigned int type.
- size_t str_size = 0, i = 0;
- int alphabet = 0;
- // string: char array
- // You should initialize them for safety.
- char word[BUFFERSIZE] = "", wordindex[BUFFERSIZE] = "";
- // You may need a buffer.
- char buffer[BUFFERSIZE] = "";
- printf("Enter your desired word or sentence: ");
- // string word, its name is a pointer.
- //scanf("%s", word);
- // get a string for a line.
- gets(word);
- // let strlen return size_t type.
- str_size = strlen(word);
- for (i = 0; i < str_size; i ++)
- {
- alphabet = (int)word[i];
- itoa( alphabet, buffer, 2);
- strcat( wordindex, buffer);
- }
- // print binary string.
- printf("%s\n", wordindex);
- }
- void main(void)
- {
- sample();
- system("PAUSE");
- }
Add Comment
Please, Sign In to add comment