我正在研究这个问题,但它有一些奇怪的错误。问题出在“替换”功能中。我在下面的代码中评论了这个问题。
我创建了三个动态字符数组(sentence,word1,word2)并使用cin.getline进行输入。我想做的是,如果:
句子=“我喜欢披萨”,
word1 =“like”和
word2 =“讨厌”
然后我想要句子=“我讨厌披萨”。
这也是我第一次使用堆栈溢出,所以如果这个帖子有问题请告诉我。非常感谢您的帮助。
void Replace(char* s, char* w1, char* w2)
{
int lisw = 0; //lisw = letters in single word
bool found = false;
for (int i = 0; s[i] != '\0' || found == true; i++)
{
lisw = 0;
//Problem is down here. The loop doesn't terminate when encountering a
//space character. When i used static_cast code to check the ASCII
//values only junk values were output. If i just cout<<s; then there is
//no problem but doing it here causes some weird logical errors.
for (int j = i; s[j] != ' '; j++)
{
lisw++;
cout << static_cast<int>(s[j]);
}
found = true;
for (int j = i; j < lisw; j++)
{
if (s[j] != w1[j])
{
found = false;
}
}
if (found == true)
{
for (int j = i; j < lisw; j++)
{
s[j] = w2[j];
}
}
i = i + lisw;
}
}
答案 0 :(得分:0)
好的,所以我通过评论找到了解决方案。我将复制下面更正的代码。更正可以在评论中看到。
fileChange(event){
if (event.target.files && event.target.files[0]) {
let imageFiles = [];
for (var i = 0; i < event.target.files.length; i++) {
let reader = new FileReader();
reader.readAsDataURL(event.target.files[i]);
reader.onload = (e) => {
imageFiles[i] = e.target.result;
console.log(e.target.result);
};
}
console.log(imageFiles);
console.log(imageFiles[0]);
}
}
//console result:
//"base64 string"
//[]-> 0: "base64 string"
//undefined