小编esp*_*all的帖子

永远不会达到其他条款

我似乎在编写字符串搜索功能时遇到问题.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)

c

3
推荐指数
1
解决办法
176
查看次数

查找和替换文本文件输出中的单词

我对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)

haskell

1
推荐指数
1
解决办法
1595
查看次数

标签 统计

c ×1

haskell ×1