프로그래밍에 약간 익숙해서 문제를 해결하지 못했지만 작업을 완료하려고 시도했습니다. 여러 가지 방법.다른 배열에서 수정 된 배열의 가비지 값을 함수에서 계속 얻습니다.
문제는 내가 단어 배열을 가져와 배열에서 구두점을 제거하고 새 단어를 별도의 배열에 배치하려고한다는 것입니다. 나는이 작업을 시도했지만 새 배열을 출력 할 때 가비지 값을 계속 유지합니다.
코드 읽
norm(sepwords1,sepwords2,numwords); <- where I called it in main
void norm(string words[], string wordz[],int count)
{
int i;
int x;
string newstring="";
char current;
for(i=0; i<count; i++)
{
for(x=0; x<words[i].length();x++)
{
current= words[i].at(x);
if(ispunct(current)==0)
{
newstring += current;
}
}
wordz[i]= newstring;
}
}
전체의 주요 기능은 다음과
int main (int argc, char* argv[])
{
int count = argc;
int i;
string filename[count];
ifstream infile;
string fromfile[1000];
int numdata;
int pass;
char current;
int sum;
string masterstring="";
int x;
string sepwords[2000];
int sum1;
string temp="";
int start;
int fin;
string newstring="";
string newfile[1000];
int place;
int numwords;
string sepwords1[2000];
string newmaster="";
int j=0;
string currentz;
string highmark;
int index[2000];
string sepwords2[2000];
int counta=0;
for(i=0; i < count-1; i++)
{
filename[i] = argv[i+1];
}
for(i=0; i < count-1; i++)
{
infile.open(filename[i].c_str());
numdata=0;
while(!infile.eof())
{
getline(infile, fromfile[numdata], '\n');
numdata++;
}
for(i=0; i<numdata; i++)
{
cout<<fromfile[i]<<endl;
masterstring += fromfile[i] + " "; //NUMBER ONE
}
numwords = split(masterstring, sepwords);
cout<<numwords<<endl; //NUMBER TWO
}
for(i=0;i<numwords;i++)
{
newstring = toupper(sepwords[i].at(0));
newstring += sepwords[i].substr(1);
sepwords1[i] = newstring;
newstring="";
}
for(i=0;i<numwords;i++)
{
newmaster += sepwords1[i] + " ";
j++;
if(j > 10)
{
newmaster+= '\n';
j=0;
}
}
cout<<newmaster<<endl; //NUMBER THREE
norm(sepwords1,sepwords2,numwords);
for(i=0;i<numwords;i++)
{
cout<<sepwords2<<endl;
}
return 0;
}
'norm'으로 전달한 원래 배열을 어떻게 선언합니까? 이 문자열 목록이 변수가 될 수 있다고 가정 할 때 배열을 사용하는 이유가'std :: vector'가 아닌가요? – birryree
외부 루프의 반복마다 newstring = ""을 원한다고 생각합니다. – jfs
코드를 구현하는 방법을 알지 못해 벡터를 사용하지 않았습니다. P – Sam