Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Replace string to char[]
    primarykey
    data
    text
    <p>I have the following c++ program that multiple 2 large numbers :</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #define OVERFLOW 2 #define ROW b_len #define COL a_len+b_len+OVERFLOW using namespace std; int getCarry(int num) { int carry = 0; if(num&gt;=10) { while(num!=0) { carry = num %10; num = num/10; } } else carry = 0; return carry; } int num(char a) { return int(a)-48; } string mult(string a, string b) { string ret; int a_len = a.length(); int b_len = b.length(); int mat[ROW][COL]; for(int i =0; i&lt;ROW; ++i) { for(int j=0; j&lt;COL; ++j) { mat[i][j] = 0; } } int carry=0, n,x=a_len-1,y=b_len-1; for(int i=0; i&lt;ROW; ++i) { x=a_len-1; carry = 0; for(int j=(COL-1)-i; j&gt;=0; --j) { if((x&gt;=0)&amp;&amp;(y&gt;=0)) { n = (num(a[x])*num(b[y]))+carry; mat[i][j] = n%10; carry = getCarry(n); } else if((x&gt;=-1)&amp;&amp;(y&gt;=-1)) mat[i][j] = carry; x=x-1; } y=y-1; } carry = 0; int sum_arr[COL]; for(int i =0; i&lt;COL; ++i) sum_arr[i] = 0; for(int i=0; i&lt;ROW; ++i) { for(int j=COL-1; j&gt;=0; --j) { sum_arr[j] += (mat[i][j]); } } int temp; for(int i=COL-1; i&gt;=0; --i) { sum_arr[i] += carry; temp = sum_arr[i]; sum_arr[i] = sum_arr[i]%10; carry = getCarry(temp); } for(int i=0; i&lt;COL; ++i) { ret.push_back(char(sum_arr[i]+48)); } while(ret[0]=='0'){ ret = ret.substr(1,ret.length()-1); } return ret; } void printhuge(string a) { cout&lt;&lt;"\n"; for(string::iterator i = a.begin(); i!=a.end(); ++i) { cout&lt;&lt;*i; } } int main() { string a,b; cin&gt;&gt;a&gt;&gt;b; printhuge(mult(a,b)); return 0; } </code></pre> <p>All is working fine, but I need to use char[] instead of "string" . I know it's silly but I have to use that format necessary. So - how can I convert the code to work with char[] definition ?</p> <p>Any ideas is greatly appreciated, Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload