未定义的引用`strlwr'

mrt*_*ccn 10 c string linker-errors

我的代码就像一个文本压缩器,读取普通文本并变成数字,每个单词都有一个数字.它在DevC++中编译但不会结束,但是它不能在Ubuntu 13.10中编译.我收到的错误就像Ubuntu中的标题"未定义引用`strlwr'",我的代码有点长,所以我无法在这里发布,但其中一个错误来自:

//operatinal funcitons here


int main()
{

    int i = 0, select;

    char filename[50], textword[40], find[20], insert[20], delete[20];

    FILE *fp, *fp2, *fp3;

    printf("Enter the file name: ");

    fflush(stdout);

    scanf("%s", filename);

    fp = fopen(filename, "r");

    fp2 = fopen("yazi.txt", "w+");

    while (fp == NULL)
    {

        printf("Wrong file name, please enter file name again: ");

        fflush(stdout);

        scanf("%s", filename);

        fp = fopen(filename, "r");

    }

    while (!feof(fp))

    {

         while(fscanf(fp, "%s", textword) == 1)

        {

            strlwr(textword);

            while (!ispunct(textword[i]))
            i++;

            if (ispunct(textword[i]))

            {

                i = 0;

                while (textword[i] != '\0')
                i++;

                i--;

                while (ispunct(textword[i]))
                i--;

                i++;

                i=0;

                while (isalpha(textword[i]))
                i++;

                textword[i] = '\0';

            }

            addNode(textword);

        }

    }

.... //main continues
Run Code Online (Sandbox Code Playgroud)

P.P*_*.P. 21

strlwr()不是标准C功能.可能它是由一个实现提供的,而您使用的其他编译器则没有.

您可以自己轻松实现它:

#include <string.h>
#include<ctype.h>

char *strlwr(char *str)
{
  unsigned char *p = (unsigned char *)str;

  while (*p) {
     *p = tolower((unsigned char)*p);
      p++;
  }

  return str;
}
Run Code Online (Sandbox Code Playgroud)