Error running STRLWR function under Linux: LD returned 1 exit status

Source: Internet
Author: User

Run the STRLWR function times wrong, the source program is as follows:

#include <stdio.h> #include <string.h>void main () {char s[10]={"China"}; printf ("%s\n", STRLWR (s)); return 0 ;}
The error content is as follows:
eg6527a.c:in function ' main ':
Eg6527a.c:8:2:warning: ' Return ' with a value, in function returning void [enabled by default] return 0; ^in file included from Eg6527a.c:3:0:eg6527a.c:at top level:/usr/include/strlwr.h:1:14:warning: ' strlwr ' used but never              defined [enabled by default] static char *strlwr (char *s); ^/tmp/cc6lxd8t.o:in function ' main ': eg6527a.c: (. text+0x79): Undefined reference to ' STRLWR ' Collect2:error:ld returned 1 exit status
Look for the reason, originally is the compatibility problem strlwr, the STRUPR function is not the standard C function library, can only use in the VC,

You need to define these functions yourself under Linux gcc.

The following are the specific practices:

Write yourself a strlwr.h header file that reads as follows:

Char *strlwr (char *s) {char *str; str = s; while (*str! = ') {  if (*str >= ' A ' && *str <= ' Z ') {     *s TR + = ' A '-' a '; } str++; } return s; }
Save it in the/usr/include directory

Then modify the source file to:

#include <stdio.h> #include <string.h> #include <strlwr.h>void main () {char s[10]={"China"}; printf (" %s\n ", STRLWR (s)); return 0;}


Run the program again at this time Gcc-o 6527a 6527a.c

Generate executable file 6527a

Run the file./6527a

The result is: China

Convert the string "China" to: "China"



Error running STRLWR function under Linux: LD returned 1 exit status

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.