What is wrong with this code in string reversal? [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}

There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;

Related

How to use comparison operator correctly in this case? (string array[0][0] == "string") [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I need to compare a character in a string that is in an array with another string. This is a functioning but simple version of my problem:
#include <iostream>
using namespace std;
int main() {
string a_ray[1] = {"asd"};
if (a_ray[0][0] == "a") {
bool a;
}
return 0;
}
Error message: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
What causes this? And how can I do what I want to do in the correct way?
Thank you in advance!
Since you are comparing against a character, your code should be
if (a_ray[0][0] == 'a')
You are trying to compare a character with a character array, hence the error message.

c++ exception : throwing std::exception [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I need to throw std::exeption if rad is negetive number, how can I throw?
void Circle::setRad(double rad) {
if (rad < 0)
{
throw(std::exception );
}
radius = rad;
}
Usually you should throw one of the derived classes:
throw std::invalid_argument("radius must be nonnegative");

error: 'listOfColors' was not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.

c++ template expected primary expression before [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm new to templates and couldn't find the answer to my problem on the forums here, maybe I just don't know what to search for exactly.
My code:
template<class T>
vector<T> properDivisors(T input) {
vector<T>retVal;
for(T d = T()+1;d<input;d++) {
if((double)input/(double)d == input/d)
retVal.push_back(d);
}
return retVal;
}
template<class T>
T sumTypeOf(T input) {
vector<T>divisors = properDivisors(T);
return someEnum;
}
When compiling I get an error on the line:
vector<T>divisors = properDivisors(T);
The error is:
error: expected primary-expression before ')' token
You need to pass a value, not a type:
vector<T> divisors = properDivisors(input);
// ^^^^^
Hah! Sorry everyone, the problem was that I should have written properDivisors(input)
Stupid nub error... sorry...

c++ problem with enum and struct [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
why doesn't this compile:
enum E { a, b}
typedef struct { int i; E e; } S;
int main(){return 0;}
I get different errors on different system.
You need a semicolon after the enum.
enum E { a, b};
There is no semicolon after the enum.
no semi colon at the end of enum
The enum needs an ; after its }