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