2016-09-28 1 views
-4

私の関数が1つのchar []を読み込み、それを2つの配列に分割します。どちらの配列も1つの大きな数値になります。最初の配列はその数値のint値であり、2つ目の値はdouble値です。この数は2進数、10進数、8進数、16進数のいずれでもかまいませんので、2つの配列を使用する必要があります。'。'の前の記号を数える方法シンボルを分割し、char []をC++の2つの配列に分割しますか?

void Read(int place[], int &size, int &type, int placedot[], int &sizedot, int &typedot) 
{ 
    char reader[limit]; 

    cin >> reader; 

    size = 1; 

    while (reader[size] == '.' || size != strlen(reader)) 
    { 
     size++; 
     cout << "LOL"; 
    } 

    cin >> type; 
    cout << size; 

    typedot = type; 

    for (int i = 0; i<size; i++) 
    { 
     switch (reader[i]) 
     { 
      case '0': place[i] = 0; break; 
      case '1': place[i] = 1; break; 
      case '2': place[i] = 2; break; 
      case '3': place[i] = 3; break; 
      case '4': place[i] = 4; break; 
      case '5': place[i] = 5; break; 
      case '6': place[i] = 6; break; 
      case '7': place[i] = 7; break; 
      case '8': place[i] = 8; break; 
      case '9': place[i] = 9; break; 
      case 'A': place[i] = 10; break; 
      case 'B': place[i] = 11; break; 
      case 'C': place[i] = 12; break; 
      case 'D': place[i] = 13; break; 
      case 'E': place[i] = 14; break; 
      case 'F': place[i] = 15; break; 
     } 
    } 
} 
+4

あなたが入力し、期待される出力の例を示していることはできますか? – NathanOliver

+0

現在のコードの問題点を教えてください。 –

+0

okeyたとえば、もし私があなたが "3.124566"と入力すると、2と3と124566の配列に分割され、最初の1と2の長さが得られるとします。 – GaBoKaS

答えて

0
#include <iostream> 
#include <string> 

int main() 
{ 
    std::string str = "3423432432.32445654576654578978905"; 
    std::string strInt; 
    std::string strDec; 

    int i = 0; 

    while('.' != str[i]) 
     strInt += str[i++]; 

    for(++i; i < str.length(); i++) 
     strDec += str[i]; 


    std::cout << strInt << std::endl << strDec << std::endl; 

    // now you have the integer part and the decimal part as strings so convert each of them to int 

    std::cout << std::endl; 
    return 0; 
} 
関連する問題