- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我有一个函数,它逐个字符地接收文件输入,并将字符形成为句子以进行修改。在这种情况下,要进行的修改之一是对句子进行处理。这将需要两个句子并通过删除它们之间的标点并将它们连接起来而形成一个连续句子。
这是我的代码:
void runOn(char sentence, ifstream & fin, int counter)
{
char ch;
int sentCounter = 0;
bool sentenceEnd = false;
while(sentCounter<=2)
{
char tempSent[SENT_LENGTH];;
do
{
fin.get(ch);
for(int i = 0; i<SENT_LENGTH;i++)
{
tempSent[i] = ch;
}
if(ch == '.' || ch == '?' || ch == '!')
{
sentCounter++;
sentenceEnd = true;
}
}while(sentenceEnd == false);
strcat(sentence,tempSent);
}
}
function.cpp:36:29: error: invalid conversion from 'char' to 'char*' [-fpermissive]
strcat(sentence,tempSent);
最佳答案
错误非常明显,strcat
声明为char * strcat ( char * destination, const char * source );
,但是sentence
不是char*
,您必须将sentence
从char
转换为char*
。
由于我不知道sentence
的来源,因此我无法提供进一步的建议,可能是您应该发布称为runOn
的函数。
也许您可以简单地将void runOn(char sentence, ifstream & fin, int counter)
更改为void runOn(char* sentence, ifstream & fin, int counter)
参见strcat
的声明here
关于c++ - 从 'char'到 'char*' strcat函数的无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43316317/
这个问题在这里已经有了答案: implicit declaration of function itoa is invalid in c99 (3 个答案) C strcat - warning:
这个问题在这里已经有了答案: Why do I first have to strcpy() before strcat()? (5 个答案) 关闭 3 年前。 如题,我做了一个demo来说明一下我
我在使用下面的程序时遇到问题。我正在尝试扫描用户输入的特定单词的字符串命令。我现在的主要问题是,当我运行以下命令时,我收到一条警告,指出“传递 ‘strcat’ 的 arg 2 使指针来自整数而不进行
我知道发生这个 valgrind 错误是因为我试图使用未初始化的东西。下面的代码是导致此错误的代码。它正在做的是尝试读取 Racket 代码并获取每个符号,例如 + 或 define。 (标记化)我不
原型 extern char *strcat(char *dest,char *src); 用法 &n
让我们举个例子。 #include #include int main() { char str1[7] = "hello "; printf("Initial size of s
我试图在不改变单词顺序的情况下颠倒一个句子, 例如:"Hello World"=> "olleH dlroW" 这是我的代码: #include #include char * reverseWo
根据Allocate string (char*) in another function我现在有这样的代码: void someFunction(char** string, char** arg
我想不通。当我在我的 Windows 机器上使用 Code::Blocks 编译这段代码时,它工作得很好,但是当我尝试在 Cygwin 或学校的实际 Unix 机器下使用 Make 编译它时,我得到下
我在一些遗留代码中发现了这一点。 static char title1[] = "SUMMARY REPORT"; static char title2[] = "PERIOD: "; ... str
我正在尝试使用 C 中的指针和 strcat。这是我学习过程的一部分。 想法是用户输入一个包含数字的字符串,输出应该只返回数字。所以,如果用户输入te12abc 输出应该是 12。 这是我的第一次尝试
在对字符串进行一些程序时,我遇到了这个小问题。他们向我提出的问题是——编写函数 strcat(s,t) 的指针版本,它将字符串 t 复制到 s 的末尾。我把程序写成这样 - #include void
我在 strcat 和段错误方面遇到了一些问题。错误如下: Program received signal EXC_BAD_ACCESS, Could not access memory. Reaso
当运行以下故意堆栈粉碎代码时,strcat 将 source 的值复制十次。 #include #include int main() { char a[16]; char b[1
我在 C 中有一个函数,我试图从两个不同的位置(未知大小,可能很大)获取字符串并将它们组合成一个字符串并返回它们。如果我只打印两个字符串,那么我会得到正确的结果,但是当我尝试使用 strcat 组合字
void mystrcat(char* to, const char* from) { while (*to) to++; while (*from) *to++ = *from++;
这是 295c 的问题之一 #include #include main() { char *a="kammo DJ";
我需要用 C 语言编写一个 strcat。我尝试了以下操作: char * c_strcat( char * str1, const char * str2) { char * ret
我正在从文件中读取行,并且我决定按 char 逐个读取 char 中的部分内容。这是我得到的: char str[500]; // it has to be this size, I promi
这个问题已经有答案了: Can I copy a string in an empty string? (3 个回答) 已关闭 8 年前。 自学C语言充满惊喜。我做这个简短的片段来测试 strcat(
我是一名优秀的程序员,十分优秀!