Hey all,
I'm trying to use strcat with input as follows:
top is declared asCode:strcat(top, input[y]); // where y is a loop var
char top[256] = ""; // but is later filled
and input is
char input[256];
(these aren't my actual variable names, however).
Unfortunately my compiler says "Invalid conversion from 'char' to 'const char*'" (gcc in KDevelop)
What should I do?
Here is all of the code just in case (a work in progress!):
Code:#include <iostream> #include <cstring> using namespace std; int main() { char input[256]; char top[256] = ""; float ftop; char bottom[256] = ""; float fbottom; int input_length; bool divide = false; float answer; char *pointer; char *pointer2; cout << "This program adds, subtracts, multiplies and divides fractions."; cout << endl << "(or it will when I'm done)" << endl; cout << "Enter a fractional number: (i.e. 5/2)" << endl; cin.get(input, 256); input_length = strlen(input); for(int x = 0; x < input_length; x++) { if(input[x] > 48 && input[x] < 57) { for(int y = x; input[y] > 48 && input[y] < 57; y++) // take in all numerical digits { if(divide == false) { pointer2 = &input[y]; strcat(top, input[y]); // puts it in top of / hasn't been encountered } if(divide == true) { pointer2 = &input[y]; strcat(bottom, input[y]); // puts them in bottom if it has } } } if(input[x] == '/') divide = true; if(input[x] == '\0'); else cout << "Invalid input."; } ftop = atoi(top); fbottom = atoi(bottom); answer = ftop/fbottom; cout << answer; return 0; }



LinkBack URL
About LinkBacks



