Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Pass String Arguments

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 Examples

Was this topic helpful?