Linux Linux program Exercise VI

Source: Internet
Author: User

Title: Implementation of a so library filename called a listupper.so,so file implements a function with the function named void Upper (constchar char *desc),
When update is called, all characters in the string pointed to by the parameter src are converted to uppercase letters, and the result is placed in the DESC string. Write a program test1 in C language respectively,
Call the upper function in libupper.so, write a program test2 in the C + + language, and invoke the upper function in libupper.so.

Upper.h

// compatible with g++ compilers #ifdef __cplusplus extern " C " {#endifvoid Upper (constChar * src,char *desc); Ifdef __cplusplus}#endif

Upper.c

/*based on function signature analysis, DESC is called function to allocate memory*/#include<stdio.h>voidUpperConst Char* SRC,Char*desc) {    if(src==null| | desc==NULL) {printf ("the incoming parameter cannot be empty! \ n"); return; }     while(*src) {        if(*src> the&&*src<123)        {            //indicates that the character is a lowercase letter*desc++=*src- +; SRC++; }Else        {            *desc++=*src++; }    }}

test1.c

#include <stdio.h>#include<unistd.h>#include"Upper.h"intMainintArgChar*args[]) {printf ("Please enter a string no more than 100 bytes in size! \ n"); Charbuf[ -]={0}; Chardesc[ -]={0}; intnum=0; Num=read (Stdin_fileno,buf,sizeof(BUF)); if(num==0)return 0;    Upper (BUF,DESC); printf ("\ n The string that the user entered is:%s", DESC); return 0;}

Run results

Linux Linux program Exercise VI

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.