我似乎在编写字符串搜索功能时遇到问题.strlength和strmid都是以前编写的功能,已经过测试并且正在工作.
int strfind(char * string1, char * string2)
{
/* if string1 contains the substring string2 returns
the starting position of string2 in string1
otherwise returns -1
e.g. strinc("hello world","wor") returns 6
strinc("hello world","war") returns -1
*/
int begPos = 0, endPos, count = 0, match = 1;
char *tempStr;
endPos = strlength(string2)-1;
while (endPos <= strlength(string1)-1)
{
strmid(string1, begPos, endPos, tempStr);
while (match == 1)
{
if (tempStr[count] == string2[count]) {
if (count < strlength(string2)) count++;
else break;
} …Run Code Online (Sandbox Code Playgroud) 我对haskell失败了,我在尝试让这个脚本工作时遇到了很多麻烦.目的是让它从命令行读取参数并在单独的文本文件中找到它们.然后将这些单词替换为与单词长度相同数量的星号.我设法让它找到替换字,但从那以后就撞墙了.我尝试了各种各样的,并希望有人能够为我澄清它.
module Main where
import System
import Data.Char
lowercase = map toLower
main = do (arg1:arg2:arg3:arg4:arg5:_) <- getArgs
txt <- getContents
putStr ( redact txt arg1 arg2 arg3 arg4 arg5 )
redact file w1 w2 w3 w4 w5 = unlines [ process line | line <- lines file ]
where process line = unwords [ f word | word <- words line ]
f w | lowercase(w) == lowercase(w1) = convertWord w 1
| lowercase(w) == lowercase(w2) = convertWord w …Run Code Online (Sandbox Code Playgroud)