需要帮助,你能找到错误??? [英] Need Help, Can you find the error???

查看:58
本文介绍了需要帮助,你能找到错误???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

现在在string-class一章中我的作业在Word计数器下面:

编写一个函数,接受指向C-String的指针作为参数

并返回字符串中包含的单词数。例如,如果字符串参数是四分和七年前,那么

函数

应返回数字6.在程序中演示函数

要求用户输入字符串然后将其传递给函数。字符串中的

字数

应该显示在屏幕上。它还应该显示

每个字的平均字母数。

这是我的程序的开始

我收到两个错误:LNK2001:未解析的外部符号" char

__cdecl wordCount(char )" (?wordCount @@ YADD @ Z)

Debug / 1.exe:致命错误LNK1120:1个未解析的外部

------------ -------------------------------------------------- ------------- * -----------------

#include< iostream>

#include< string>

#include< iomanip>

#include< ctype.h>

using namespace std ;

char wordCount(char);

int main()

{

char cstring [81];

cout<< " \ n输入一个字符串,不超过80个字符:\ n" ;;

cin.getline(cstring,81);

cout<< \ n该字符串中的单词数:" ;;

cout<< wordCount(cstring [81])<< endl;

返回0;

}

char wordCount(char cstring [81])

{

int index = 0;

int word = 0;

while(cstring [index]!=''\''') />
{

if(isspace(cstring [index]))

{

while(isspace(cstring [index] ))

{

index ++;

}

}

if(isalnum) (cstring [index]))

{

word ++; //我们必须在一个单词

while(islower(cstring [index]))

{

word ++;

}

}

索引++;

}

返回cstring [word];


}

--------------------------------- ------------------------------------------ *

任何人都可以找到错误并提出修改建议。

------

Ash

Hi!
now on the chapter "string-class" My assignment is below Word Counter:
Write a function that accepts a pointer to a C-String as an argument
and returns the number of words contained in the string. For instance,
if the string argument is "Four score and seven years ago" the function
should return the number 6. Demonstrate the function in a program that
asks the user to input a string and then passes it to the function. The
number of words
in the string should be displayed on the screen.It should also display
the average number of letters in each word.
Here is the begining of my program
I am getting two errors: LNK2001: unresolved external symbol "char
__cdecl wordCount(char)" (?wordCount@@YADD@Z)
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
---------------------------------------------------------------------------*-----------------
#include <iostream>
#include <string>
#include <iomanip>
#include <ctype.h>
using namespace std;
char wordCount(char );
int main()
{
char cstring[81];
cout << "\nEnter a string, 80 or fewer characters:\n";
cin.getline(cstring, 81);
cout << "\nThe number of words in that string: ";
cout << wordCount(cstring[81]) << endl;
return 0;
}
char wordCount(char cstring[81])
{
int index = 0;
int word = 0;
while (cstring[index] != ''\0'')
{
if (isspace(cstring[index]))
{
while (isspace(cstring[index]))
{
index++;
}
}
if (isalnum(cstring[index]))
{
word++; //we must be in a word
while(islower(cstring[index]))
{
word++;
}
}
index++;
}
return cstring[word];

}
---------------------------------------------------------------------------*
can anyone find the error and perhaps make a suggestion to fix it.
------
Ash

推荐答案

< as ******* @ yahoo.com>在消息中写道

新闻:11 ********************** @ o13g2000cwo.googlegr oups.com ...

嗨!

现在在string-class一章中我的作业在Word计数器下面:

编写一个函数,接受指向C-String的指针作为参数

并返回字符串中包含的单词数。例如,如果字符串参数是四分和七年前,那么

函数

应返回数字6.在程序中演示函数

要求用户输入字符串然后将其传递给函数。字符串中的

字数

应该显示在屏幕上。它还应该显示

每个字的平均字母数。

这是我的程序的开始

我收到两个错误:LNK2001:未解析的外部符号" char

__cdecl wordCount(char )" (?wordCount @@ YADD @ Z)

Debug / 1.exe:致命错误LNK1120:1个未解析的外部

------------ -------------------------------------------------- ------------- * -----------------

#include< iostream>

#include< string>

#include< iomanip>

#include< ctype.h>

using namespace std ;

char wordCount(char);


***这里你声明一个函数接受单个字符作为

参数

***修复此项以符合下面的实际功能。


int main()

{

char cstring [81];

cout<< " \ n输入一个字符串,不超过80个字符:\ n" ;;

cin.getline(cstring,81);

cout<< \ n该字符串中的单词数:" ;;

cout<< wordCount(cstring [81])<< endl;

返回0;

}

char wordCount(char cstring [81])

***在这里你声明一个函数接受81个字符的数组作为

a参数

{

int index = 0;

int word = 0;

while(cstring [index]!=''\''')

{

if(isspace(cstring [index]))

{

while(isspace(cstring [index]))

{

index ++;

}

}

if(isalnum(cstring [index]))

{

word ++; //我们必须在一个单词

while(islower(cstring [index]))

{

word ++;

}

}

索引++;

}

返回cstring [word];


}
<as*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi!
now on the chapter "string-class" My assignment is below Word Counter:
Write a function that accepts a pointer to a C-String as an argument
and returns the number of words contained in the string. For instance,
if the string argument is "Four score and seven years ago" the function
should return the number 6. Demonstrate the function in a program that
asks the user to input a string and then passes it to the function. The
number of words
in the string should be displayed on the screen.It should also display
the average number of letters in each word.
Here is the begining of my program
I am getting two errors: LNK2001: unresolved external symbol "char
__cdecl wordCount(char)" (?wordCount@@YADD@Z)
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
---------------------------------------------------------------------------*-----------------
#include <iostream>
#include <string>
#include <iomanip>
#include <ctype.h>
using namespace std;
char wordCount(char );

*** Here you''re declaring a function accepting a single character as a
parameter
*** Fix this to match your actual function below.

int main()
{
char cstring[81];
cout << "\nEnter a string, 80 or fewer characters:\n";
cin.getline(cstring, 81);
cout << "\nThe number of words in that string: ";
cout << wordCount(cstring[81]) << endl;
return 0;
}
char wordCount(char cstring[81])
*** Here you''re declaring a function accepting an array of 81 characters as
a parameter
{
int index = 0;
int word = 0;
while (cstring[index] != ''\0'')
{
if (isspace(cstring[index]))
{
while (isspace(cstring[index]))
{
index++;
}
}
if (isalnum(cstring[index]))
{
word++; //we must be in a word
while(islower(cstring[index]))
{
word++;
}
}
index++;
}
return cstring[word];

}




" Jim Langston" < TA ******* @ rocketmail.com>在消息中写道

news:z6 ******************* @ fe04.lga ...

"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:z6*******************@fe04.lga...
< as*******@yahoo.com>在消息中写道
新闻:11 ********************** @ o13g2000cwo.googlegr oups.com ...
嗨!
现在在章节string-class上我的作业在Word Counter下面:
编写一个函数,接受一个指向C-String的指针作为参数
并返回字符串中包含的单词数。例如,如果字符串参数是四分和七年前,则
函数
应该返回数字6.在一个程序中演示函数,该函数要求用户输入一个字符串,然后将其传递给函数。字符串中的单词数量应该显示在屏幕上。它还应该显示每个单词的平均字母数。
这是我程序的开头
我收到两个错误:LNK2001:未解析的外部符号" char
__cdecl wordCount(char)" (?wordCount @@ YADD @ Z)
Debug / 1.exe:致命错误LNK1120:1未解析的外部
-------------------- -------------------------------------------------- ----- * -----------------
#include< iostream>
#include< string>
#include< ; iomanip>
#include< ctype.h>
使用命名空间std;
char wordCount(char);

***在这里你宣布接受单个字符作为
参数的函数
***修复此问题以匹配下面的实际功能。

int main()
{
char cstring [81];

cout<< " \\\
输入一个字符串,不超过80个字符:\ n" ;;
cin.getline(cstring,81);
cout<< " \ n该字符串中的单词数:" ;;
cout<< wordCount(cstring [81])<< ENDL;


***此外,为什么你不打电话给wordCount(cstring)?

返回0;

}

char wordCount(char cstring [81])
***这里你声明一个函数接受81个字符的数组
作为参数
{
int index = 0;
int word = 0;
while(cstring [index]!=''\ 0'')
{
if( isspace(cstring [index]))
{while /(isspace(cstring [index]))
{
索引++;
}
}
if(isalnum(cstring [index]))
{
word ++; //我们必须在一个单词
while(islower(cstring [index]))
{
word ++;
}
}
index ++;
}
返回cstring [word];


***你想回到这里的是什么?你真的不想回复

的单词数量?我认为你的功能需要工作。

}
<as*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi!
now on the chapter "string-class" My assignment is below Word Counter:
Write a function that accepts a pointer to a C-String as an argument
and returns the number of words contained in the string. For instance,
if the string argument is "Four score and seven years ago" the function
should return the number 6. Demonstrate the function in a program that
asks the user to input a string and then passes it to the function. The
number of words
in the string should be displayed on the screen.It should also display
the average number of letters in each word.
Here is the begining of my program
I am getting two errors: LNK2001: unresolved external symbol "char
__cdecl wordCount(char)" (?wordCount@@YADD@Z)
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
---------------------------------------------------------------------------*-----------------
#include <iostream>
#include <string>
#include <iomanip>
#include <ctype.h>
using namespace std;
char wordCount(char );

*** Here you''re declaring a function accepting a single character as a
parameter
*** Fix this to match your actual function below.

int main()
{
char cstring[81];
cout << "\nEnter a string, 80 or fewer characters:\n";
cin.getline(cstring, 81);
cout << "\nThe number of words in that string: ";
cout << wordCount(cstring[81]) << endl;
*** Also, here, why aren''t you calling wordCount(cstring) ?
return 0;
}
char wordCount(char cstring[81])
*** Here you''re declaring a function accepting an array of 81 characters
as a parameter
{
int index = 0;
int word = 0;
while (cstring[index] != ''\0'')
{
if (isspace(cstring[index]))
{
while (isspace(cstring[index]))
{
index++;
}
}
if (isalnum(cstring[index]))
{
word++; //we must be in a word
while(islower(cstring[index]))
{
word++;
}
}
index++;
}
return cstring[word];
*** What are you trying to return here? Doen''t you actually want to return
the number of words? I think your function needs work.

}



这次没有错误,但是当它被淘汰时,我我被要求输入一个字符串。

但它在单词行数后停止。

#include< iostream>

#include < string>

#include< iomanip>

#include< ctype.h>

using namespace std;

char wordCount(char []);

int main()

{

char cstring [81];

int index = 0;

cout<< Arshdeep Kaur撰写,Cs102 online\\\
;

cout<< " \ n输入一个字符串,不超过80个字符:\ n" ;;

cin.getline(cstring,81);

cout<< " \ n该字符串中的单词数:" ;;

wordCount(cstring);

cout<< index<< endl;

返回0;

}

char wordCount(char cstring [])

{

int index = 0;

int word = 0;

while(cstring [index]!=''\ 0'')

{

if(isspace(cstring [index]))

{

while(isspace(cstring [index]) )

{

index ++;

}

}

if(isalnum( cstring [index]))

{

word ++;

while(islower(cstring [index]))

{

word ++;

}

while((isalnum(cstring [index]))||(ispunct(cstring [index]) ))

{

word ++;

}

}

index ++;

返回索引;

}


}

我认为我的wordCount函数存在问题

no error this time but when it excutes, i''m asked to input a string.
but it stops after the line number of words.
#include <iostream>
#include <string>
#include <iomanip>
#include <ctype.h>
using namespace std;
char wordCount(char []);
int main()
{
char cstring[81];
int index = 0;
cout << "Written by Arshdeep Kaur, Cs102 online\n";
cout << "\nEnter a string, 80 or fewer characters:\n";
cin.getline(cstring, 81);
cout << "\nThe number of words in that string: ";
wordCount(cstring);
cout << index << endl;
return 0;
}
char wordCount(char cstring[])
{
int index = 0;
int word = 0;
while (cstring[index] != ''\0'')
{
if (isspace(cstring[index]))
{
while (isspace(cstring[index]))
{
index++;
}
}
if (isalnum(cstring[index]))
{
word++;
while(islower(cstring[index]))
{
word++;
}
while((isalnum(cstring[index])) || ( ispunct(cstring[index])))
{
word++;
}
}
index++;
return index;
}

}
I think there is a problem in my wordCount funtion


这篇关于需要帮助,你能找到错误???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆