字符串作为函数的输入 [英] strings as inputs to a function

查看:93
本文介绍了字符串作为函数的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个基本的拼写检查功能,其中一个具有

其参数两个字符串数组,一个是来自文件的文章

来源需要要检查有效单词,在这种情况下,

字必须至少2个字符长,没有介入

标点符号,数字或其他非字母。 />
这个单词然后需要小写,然后与

字典输入数组进行比较。最终的结果是打印出文章中拼写错误的所有单词。所有这些都需要用

来完成几个或没有指针。

有什么建议吗?

I am trying to write a basic spell check function, one which has as
its parameters two strings arrays, one is an article from a file
source which needs to be checked for valid words, in this case the
word needs to be at least 2 characters long with no intervening
punctuation, numbers or other non-letters.
This word then needs to be lower case and then compared to the
dictionary input array. the end result being the printing out of all
the misspelled words in the article. All of this needs to be done with
few or no pointers.
Any suggestions out there?

推荐答案

David W. Thorell写道:
David W. Thorell wrote:
我正在尝试编写一个基本的拼写检查功能,其中一个具有作为其参数的两个字符串数组,一个是来自的文章文件
需要检查有效单词的来源,在这种情况下,
字必须至少2个字符长,没有插入标点,数字或其他非字母。
字典输入数组进行比较。最终的结果是打印出文章中所有拼写错误的单词。所有这些都需要用很少或没有指针来完成。


为什么?

有什么建议吗?
I am trying to write a basic spell check function, one which has as
its parameters two strings arrays, one is an article from a file
source which needs to be checked for valid words, in this case the
word needs to be at least 2 characters long with no intervening
punctuation, numbers or other non-letters.
This word then needs to be lower case and then compared to the
dictionary input array. the end result being the printing out of all
the misspelled words in the article. All of this needs to be done with
few or no pointers.
Why?
Any suggestions out there?




你需要的一些功能是tolower(),fgets(),strcmp(),printf()。

尝试编写代码(这很简单)并重新发布如果遇到

问题。


HTH,

--ag



Some functions you''ll need are tolower(), fgets(), strcmp(), printf().
Try to write the code (it''s pretty simple) and repost if you run into
problems.

HTH,
--ag


" David W. Thorell写道:


[snip]
"David W. Thorell" wrote:

[snip]
然后这个单词必须是小写,然后与
字典输入数组进行比较。最终的结果是打印出文章中所有拼写错误的单词。所有这一切都需要用很少或没有指针来完成。
有什么建议吗?
This word then needs to be lower case and then compared to the
dictionary input array. the end result being the printing out of all
the misspelled words in the article. All of this needs to be done with
few or no pointers.
Any suggestions out there?




使用哈希表。


此外,您对少数的定义是什么?指针?你有一个计划

的前缀和后缀词(un-,re-,-s,-ing,-ed等)?


/ david


-

安德烈,一个简单的农民,只有一件事在他脑海中悄悄地沿着东墙:''安德烈,蠕动......安德烈,蠕动......安德烈,蠕动。''

- 未知



Use a hash table.

Also, what is your definition of "few" pointers? And do you have a plan
for prefixed and suffixed words (un-, re-, -s, -ing, -ed, etc)?

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: ''Andre, creep... Andre, creep... Andre, creep.''
-- unknown




" David W. Thorell" <峰; dt ****** @ hotmail.com>在消息中写道

"David W. Thorell" <dt******@hotmail.com> wrote in message
我正在尝试编写一个基本的拼写检查功能,其中一个具有作为其参数的两个字符串数组,一个是来自文件的文章
来源需要要检查有效单词,在这种情况下,
字必须至少2个字符长,没有插入标点符号,数字或其他非字母。
这个词需要是小写然后比较
字典输入数组。最终的结果是打印出文章中所有拼写错误的单词。所有这一切都需要用很少或没有指针来完成。
有什么建议吗?
I am trying to write a basic spell check function, one which has as
its parameters two strings arrays, one is an article from a file
source which needs to be checked for valid words, in this case the
word needs to be at least 2 characters long with no intervening
punctuation, numbers or other non-letters.
This word then needs to be lower case and then compared to the
dictionary input array. the end result being the printing out of all
the misspelled words in the article. All of this needs to be done with
few or no pointers.
Any suggestions out there?



我不明白很少或没有指针"限制。 C语言是围绕指针建立的(b ++),有一种方法可以避免使用

指针和更高级别的替代品,但这是comp.lang。 c)。


你需要一个函数


int spellcheck(char ** dictionary,int N,char * word)


假设字典按字母顺序包含所有允许的单词。


懒惰的方法就是使用strcmp()直接遍历数组。如果

你找到一个匹配,返回1,如果你到最后,返回0.


但是我们可以通过做一个事情来加快速度二分搜索。你维持

三个数字,低,高,中等。在开头低位是字典中的第一个单词

,高位是最后一个单词,中位是中间单词。说

你的单词在中间后按字母顺序排列。然后低点变为中等,高点
保持不变,中间位置变为新的中点,即三个b
四分之一。

你重复这个技巧,直到你找到一个匹配或低和高
收敛到相同的值,在这种情况下你知道这个词不在

字典中。


I don''t understand the "few or no pointers" restriction. The C language is
built around pointers (in C++ there is a move to get away from using
pointers and towards higher-level substitutes, but this is comp.lang.c).

You need a function

int spellcheck(char **dictionary, int N, char *word)

Assume the dictionary contains all allowed words in alphabetical order.

The lazy way is simply to step right through the array using strcmp(). If
you find a match, return 1, if you get to the end, return 0.

However we can speed things up a lot by doing a binary search. You maintain
three numbers, low, high, and middle. At the beginning low is the first word
in the dictionary, high is the last word, and middle is the middle word. Say
your word is alphabetically after middle. Then low becomes middle, high
stays the same, and middle becomes the new mid point, that is, the three
quarters mark.
You repeat this technique until either you find a match or low and high
converge to the same value, in which case you know the word isn''t in the
dictionary.


这篇关于字符串作为函数的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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