未定义的引用`strlwr'

时间:2014-05-12 20:32:35

标签: 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

2 个答案:

答案 0 :(得分:20)

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;
}

答案 1 :(得分:0)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* strlwr(char* );
int main() 
{
  printf("Please Enter Size Of The String: \n");
  int a,b;
  scanf("%d",&a);
  char* str;
  str=(char*)malloc(sizeof(char)*a);
  scanf("\n%[^\n]",str);
  char* x;
  x=strlwr(str);
  for(b=0;x[b]!='\0';b++)
  {
    printf("%c",x[b]);
  }
  free(str);
  return 0;
}
char* strlwr(char* x)
{
  int b;
  for(b=0;x[b]!='\0';b++)
  {
    if(x[b]>='A'&&x[b]<='Z')
    {
      x[b]=x[b]-'A'+'a';
    }
  }
  return x;
}