无法将我的字符输入从另一个输入文件转换为字符*



尝试在屏幕上显示输入。然后,使用字符串和函数将下载文件中的文本转换为pig拉丁文。这就是我到目前为止所拥有的。如果我把它分解成单独的程序,我可以让它们都工作。例如,如果我完全省略了我的功能和转换,它会根据需要成功地将我的所有输入显示在屏幕上。我需要将这些char值转换为char*,以便将它们与我的函数或我所知道的预定义字符串函数一起使用。我不知道该怎么做。

#include <iostream> // my libraries needed for files and strings
#include <cstring>
#include <fstream>
using namespace std;
void pigConfig(char*); // function used to convert input into Pig Latin
int main()
{
char inputString[101]; // string declared to hold the anticipated values and null terminator
char next;
ifstream inStream;
inStream.open("ASSGN8-A.txt"); //opening file and checking if open correctly
if (inStream.fail())
{
cout << "Input file opening failed.n";
exit(1);
}
inStream.get(next); //outputting the input to the screen
while(!inStream.eof())
{
cout << next;
inStream.get(next);
}

pigConfig(inputString); // calling on the function
inStream.close();
return 0;
}
void pigConfig(char *ptr)
{
char first = ptr[0]; //initializing char to hold first letter of first word
//use for loop to check all characters of
//string to find a space or null terminator,
//which mark the end of a word
for(int index = 1; index <= strlen(ptr); index++)
{
if(ptr[index] == ' ')
{
cout << (char)toupper(first) << "AY" << " "; //pints first letter of current word together with AY and space
first = ptr[index+1];
index++;
}
else if(ptr[index] == '') //check for end of string to run a final time
{
cout << (char)toupper(first) << "AY";
return;
}
else
cout << (char)toupper(ptr[index]);
}
}
char next;
...
strcpy(inputString,next);

strcpy函数复制字符串。但是,nextchar,而不是字符串。因此,对strcpy的调用没有任何意义。

最新更新