Created
January 2, 2010 04:28
-
-
Save johnhmj/267380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment