14ccd018b.

HTTP/1.1 200 OKServer: GlassFish Server Open Source Edition 4.1.1 X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition 4.1.1 Java/Oracle Corporation/1.8) Set-Cookie: JSESSIONID=7b070e37ebee569a27f39fef8d83; Path=/; Secure; HttpOnly Set-Cookie: MW_Doc_Template=WEB||||||||||; Path=/help Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Expires: Mon, 12 Oct 2020 12:13:30 EDT Content-Type: text/html;charset=utf-8 Date: Mon, 25 Oct 2021 13:42:45 GMT Transfer-Encoding: chunked 10042 Pass String Arguments Examples - MATLAB & Simulink - MathWorks Nordic
Main Content

Pass String Arguments Examples

stringToUpper Function

The stringToUpper function in the shrlibsample library converts the characters in the input argument to uppercase. The input parameter, char *, is a C pointer to a string.

EXPORTED_FUNCTION char* stringToUpper(char *input) 
{
   char *p = input;

   if (p != NULL)
      while (*p!=0)
         *p++ = toupper(*p);
   return input;
}

The function signature for stringToUpper is shown in the following table. MATLAB® maps the C pointer type (char *) into cstring so you can pass a MATLAB character array to the function.

Return TypeNameArguments
[cstring,
cstring]
stringToUpper(cstring)

Convert MATLAB Character Array to Uppercase

This example shows how to pass a MATLAB character array str to a C function, stringToUpper.

str = 'This was a Mixed Case string';

Load the library containing the stringToUpper function.

if not(libisloaded('shrlibsample'))
    addpath(fullfile(matlabroot,'extern','examples','shrlib'))
    loadlibrary('shrlibsample')
end

Pass str to the function.

res = calllib('shrlibsample','stringToUpper',str)
res = 
'THIS WAS A MIXED CASE STRING'

The input parameter is a pointer to type char. However, a MATLAB character array is not a pointer, so the stringToUpper function does not modify the input argument, str.

str
str = 
'This was a Mixed Case string'

Related Topics

0