vendredi 31 août 2018

Getting input X/X/etc with char X and separating it with slash /

I make program build with C++. My program is convert binary to decimal and the decimal convert to alphabet. The input is separated with slash "/"

input example :

input : 00001/00010/00011

output : abc

this is my code

#include <iostream>
#include <conio.h>
#include <cstring>

using namespace std;
int main()
{
char X[64];
int T,d=0,i=0,j;
scanf("%[^/]/%d", X);
while(X[i]!=0)
{    if(X[i]=='0'||X[i]=='1')
    {
        d=d*2+X[i]-48;
    }i++;
}
switch (d)
{
    case 1:
        cout<<"a";
        break;
    case 2:
        cout<<"b";
        break;
    case 3:
        cout<<"c";
        break;
    case 4:
        cout<<"d";
        break;
    case 5:
        cout<<"e";
        break;
    case 6:
        cout<<"f";
        break;
    case 7:
        cout<<"g";
        break;
    case 8:
        cout<<"h";
        break;
    case 9:
        cout<<"i";
        break;
    case 10:
        cout<<"j";
        break;
    case 11:
        cout<<"k";
        break;
    case 12:
        cout<<"l";
        break;
    case 13:
        cout<<"m";
        break;
    case 14:
        cout<<"n";
        break;
    case 15:
        cout<<"o";
        break;
    case 16:
        cout<<"p";
        break;
    case 17:
        cout<<"q";
        break;
    case 18:
        cout<<"r";
        break;
    case 19:
        cout<<"s";
        break;
    case 20:
        cout<<"t";
        break;
    case 21:
        cout<<"u";
        break;
    case 22:
        cout<<"v";
        break;
    case 23:
        cout<<"w";
        break;
    case 24:
        cout<<"x";
        break;
    case 25:
        cout<<"y";
        break;
    case 26:
        cout<<"z";
        break;
}
cout << endl;
}

I have used a number of ways that are still unable, and only the front binary can be read. Sorry for my bad english

Aucun commentaire:

Enregistrer un commentaire