undefined reference to `strlwr' [closed]

情到浓时终转凉″ 提交于 2019-12-17 07:37:52

问题


My code is like a text compressor, reading normal text and turns into numbers, every word has a number. It compiles in DevC++ but does not end, however, it does not compile in Ubuntu 13.10. I'm getting an error like in the title in Ubuntu "undefined reference to `strlwr'", my code is a little long so I am not able to post it here, but one of the error is from here:

//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

回答1:


strlwr() is not standard C function. Probably it's provided by one implementation while the other compiler you use don't.

You can easily implement it yourself:

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


来源:https://stackoverflow.com/questions/23618316/undefined-reference-to-strlwr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!