24:21:错误:从'char'无效转换为'char *'[-fpermissive] [英] 24:21: error: invalid conversion from 'char' to 'char*' [-fpermissive]
问题描述
#include <iostream>
#include<cstring>
using namespace std;
int count=0;
void reverseit(char st[100])
{
char *c,*d,temp;
for(int i=1;i<=count;i++)
{
c=&st[i]; //begining pointer
d=&st[count]; //last pointer
temp=*c;
st[i]=*d;
st[count]=temp;
count--;
}
}
int main() {
char ch[100];
cout<<"enter the string to reverse it";
cin.getline(ch,100);
cout.write(ch,100);
count=std::strlen(ch);
reverseit(ch[100]);
return 0;
}
无法排序2个错误
我尝试了什么:
无法解决两个错误但很难做到的事情
not able to sort 2 errors
What I have tried:
NOT ABLE TO SOLVE TWO ERRORS TRIED ALOT BUT NOT ABLE TO DO SO
推荐答案
void reverseit(char st[100])
此签名表明, reverseit
接受一个100个字符长的数组,但你用一个字符串调用它...
This signature states, that reverseit
accepts a 100 char long array, but you call it with a single char...
reverseit(ch[100]);
你应该改变它:
You should change it like this:
reverseit(ch);
当你解决上述问题时,会出现一个更大的问题,数组从索引0开始......不是1
你的循环
When you fix the above there is a much bigger problem, Arrays start at index 0 ... NOT 1
Your loop
for(int i=1;i<=count;i++)
我可以向你保证i = 1是st [1]不是这一系列的第一个字符de
I can assure you that when i=1 is st[1] is NOT THE FIRST CHARACTER from this line of code
c=&st[i]; //begining pointer
类似地,下一行不是你期望的,当i = 1时将获取#0,因此你将打印一个空字符串。 />
Similarly this next line will not be what you are expecting and will fetch #0 when i=1 and thus you will print an empty string.
d=&st[count]; //last pointer
您可能想修复这些并记住Arrays从索引0开始蚀刻它在你头脑中: - )
You might want to fix these and remember Arrays start at index 0 etch it in your head :-)
这篇关于24:21:错误:从'char'无效转换为'char *'[-fpermissive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!