Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int main(){
- int readTape( char *indexFun );
- char strInput[12], strOut[10000];
- char *index = &strInput[0];
- int ASCII;
- int cnt, power, length=0, tapeEnd=1;
- while (readTape(index)){
- /* reset variables*/
- ASCII = 0;
- power = 7;
- if (strInput[0] == '_'){
- tapeEnd = (tapeEnd == 0) ? 1 : 0 ;
- /* if it's tape's end, prints out the result */
- if (tapeEnd){
- for ( cnt=0 ; cnt<length ; cnt++ )
- printf("%c", strOut[cnt]);
- length = 0; /* reset tape's length */
- } /* END inner if*/
- continue;
- } /* END outer if */
- /* decode the tape, translate the tape into ASCII code */
- for ( cnt=1 ; cnt<10 ; cnt++ ){
- if (strInput[cnt] == 'o')
- ASCII += pow(2, power);
- power = (cnt==6) ? power : --power ;
- } /* END for */
- strOut[length++] = ASCII;
- } /* END while*/
- system("PAUSE");
- return 0;
- }
- int readTape( char *indexFun ){
- int cnt;
- for ( cnt=0 ; cnt<12 ; cnt++, indexFun++ ){
- *indexFun = getchar();
- if (*indexFun == '\n')
- return 1;
- } /* END for */
- return 0;
- } /* END readTape() */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement