Hi flexlight,

this is sample code that will solve your problem.

The idea is similar to that, you used in your code.

Program is goint through array of chars and checking

for arrays of successive digits (numbers) and puting

them in an array of numbers. At the end program prints

the first of them.

Althought, I don't understand why first of them

should be answer. :-)

Sample code:

=============

_______________________________________________________________________________

#include <iostream>

#include <cstring>

using namespace std;

const int MAX_LEN = 1000, // Maximal char array length

MAX_NUM = 500; // Maxinal number of numbers in array

int main() {

char text[MAX_LEN];

cout << "Char array: ";

cin.getline(text, MAX_LEN);

// text is array of characters that you allready have.

// so this is part of code that is particulary

// interesting for your problem.

int i = 0, len = strlen(text), number[MAX_NUM], ntop = 0;

while (true) {

while (i < len && !isdigit(text[i]))

i++;

if (i == len) break;

long num = 0;

while (i < len && isdigit(text[i])) {

num = 10*num + (text[i] - '0');

i++;

}

number[ntop++] = num;

}

// i is index of current character in array

// len is length of array

// number is array if numbers found in array

// num is current number

// ntop is index of current number

cout << "And the answer is: " << number[0] << endl;

// note that if there is no numbers in array

// number[0] will be some random number.

// this is is optional, just to show you

// that program is correct.

cout << "Other numbers: ";

for (int i = 1; i < ntop; i++)

cout << number [i] << " ";

cout << endl;

}

_______________________________________________________________________________

Sample input\output 1:

=======================

_______________________________________

Char array: f(123) + g(12) - sin(45)/tg(32) + 123*456

And the answer is: 123

Other numbers: 12 45 32 123 456

_______________________________________

Sample input\output 2:

=======================

_______________________________________

Char array: a(1+b(2+c(3)+2)+1)

And the answer is: 1

Other numbers: 2 3 2 1

_______________________________________

If I was not clear enough,

I would be glad to help.

Regards, Uros.

this is sample code that will solve your problem.

The idea is similar to that, you used in your code.

Program is goint through array of chars and checking

for arrays of successive digits (numbers) and puting

them in an array of numbers. At the end program prints

the first of them.

Althought, I don't understand why first of them

should be answer. :-)

Sample code:

=============

__________________________

#include <iostream>

#include <cstring>

using namespace std;

const int MAX_LEN = 1000, // Maximal char array length

MAX_NUM = 500; // Maxinal number of numbers in array

int main() {

char text[MAX_LEN];

cout << "Char array: ";

cin.getline(text, MAX_LEN);

// text is array of characters that you allready have.

// so this is part of code that is particulary

// interesting for your problem.

int i = 0, len = strlen(text), number[MAX_NUM], ntop = 0;

while (true) {

while (i < len && !isdigit(text[i]))

i++;

if (i == len) break;

long num = 0;

while (i < len && isdigit(text[i])) {

num = 10*num + (text[i] - '0');

i++;

}

number[ntop++] = num;

}

// i is index of current character in array

// len is length of array

// number is array if numbers found in array

// num is current number

// ntop is index of current number

cout << "And the answer is: " << number[0] << endl;

// note that if there is no numbers in array

// number[0] will be some random number.

// this is is optional, just to show you

// that program is correct.

cout << "Other numbers: ";

for (int i = 1; i < ntop; i++)

cout << number [i] << " ";

cout << endl;

}

__________________________

Sample input\output 1:

=======================

__________________________

Char array: f(123) + g(12) - sin(45)/tg(32) + 123*456

And the answer is: 123

Other numbers: 12 45 32 123 456

__________________________

Sample input\output 2:

=======================

__________________________

Char array: a(1+b(2+c(3)+2)+1)

And the answer is: 1

Other numbers: 2 3 2 1

__________________________

If I was not clear enough,

I would be glad to help.

Regards, Uros.