 # Arduino String

I have two strings, i want to multiply their each individual char, but i want it to look like Product11, Product12, Product13 … Product nm .
a,b are two strings (Examples, a = {1, 2, 3, 4} b = {2, 3} )

``````for(int i=0; i < lengthanumber; i++){
for(int j=0; j < lengthbnumber; j++) {

int Product[i,j] = a[i] * b[j]  ;

}
``````

Why doesn t this work? I mean i know why… i just want to know how i can make to look like i said in the first line.

I have two strings

No, you don't You don't even have two Strings. You have two arrays.

Why doesn t this work?

Why should it? You are trying to create a local array, of a different size on every pass through the loop. Why? That isn't even the proper syntax for a 2D array.

Aren t they strings?

`````` a = String(Serial.parseInt());
b = String(Serial.parseInt());

// int on the arduino uno = max 32,767, will use long for the result (product)

int lengthanumber = a.length() ;
int lengthbnumber = b.length() ;

for(int i=0; i < lengthanumber; i++){
for(int j=0; j < lengthbnumber; j++) {

int Product[] = a[i] * b[j]  ;

}

}
``````

Aren t they strings? a = String(Serial.parseInt()); b = String(Serial.parseInt());

Why the f**k are you making a String out of an int, if you want to multiply them? What, exactly, is elephant * house?

I want to make an algorithm for chinese multiplication.

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

I can’t read your code, it looks like gibberish without the code tags.

How to use this forum

`````` for(int i=0; i < lengthanumber; i++){
for(int j=0; j < lengthbnumber; j++) {

int Product[] = a[i] * b[j]  ;

}
``````

I suggest reading a tutorial on C programming. The result (Product) needs to be an array* to which you have allocated some sort of size, which you haven’t. Also, you can’t multiply two Strings together.

• Or it’s not an array in which case you shouldn’t have the square brackets.

I want to make an algorithm for chinese multiplication.

Perhaps you should go to China, and see how they multiply Strings. They don't. They multiply numbers!

How to i convert a char from String to a int? Something like this, so i can multiply them.

``````String a;
String b;
int lengthanumber;
int lengthbnumber;

void setup() {
// start serial port
Serial.begin(9600);
Serial.println("Type in the factors as follows : Factor1, Factor2 ");
}

void loop() {

while (Serial.available() > 0) {

// StringObject, not simple Char !

a = String(Serial.parseInt());
b = String(Serial.parseInt());

// int on the arduino uno = max 32,767, will use long for the result (product)

lengthanumber = a.length() ;
lengthbnumber = b.length() ;
int Product[lengthanumber][lengthbnumber];
int aFactor[lengthanumber];
int bFactor[lengthbnumber];

for(int i=0; i < lengthanumber; i++){
for(int j=0; j < lengthbnumber; j++) {

aFactor[i] = a[i];
bFactor[j] = b[j];
Product[i][j] = aFactor[i] * bFactor[j] ;

}
}
``````

How to i convert a char from String to a int?

This question makes NO sense. You don’t have a char anywhere!

``````   a = String(Serial.parseInt());
``````

This is STUPID. Do NOT convert the int to a String! You could have the int if you used your head.

icamaster: I want to make an algorithm for chinese multiplication.

This is one way to handle characters as numeric values.... Written for serial input: http://www.hackster.io/rayburne/scientific-calculator

You may find some insight too by researching integer division "/" and modulo "%". A very simple manual explanation to Chinese multiplication is here: http://www.instructables.com/id/How-to-Multiply-Like-Chinese-the-easy-way-Fast-/ And appears to be applicable to a software algorithm.

As for the responses that are somewhat " terse", these are meant to make you think before you ask for assistance. Those with the toughese responses are the senior members that will provide deep insight if you do your homework first.

Good luck,

Ray

PaulS:

I want to make an algorithm for chinese multiplication.

Perhaps you should go to China, and see how they multiply Strings. They don't. They multiply numbers!

OMG! I spewed my coffee on this response! :fearful:

Ray