Jump to content

C Function to convert string to upper case


dhazelman

Recommended Posts

Trying to create C function to convert a String ASCII to upper case.

This is what I tried and it does not work:

static void PrefixToUpper(volatile char* Prefix, int PrefixLen)
{
    // User code starts below this comment
    for (int i  = 0; Prefix[i] != '\0' ; i++)
        {
        if(Prefix[i] >= 'a' && Prefix[i] <= 'z')
                {
                    Prefix[i] = Prefix[i] - 32;
                }
        }
    // User code ends above this comment
}

// User code starts below this comment

Tested the code in C compiler and it runs correctly:

static void PrefixToUpper(volatile char* Prefix)
{
    // User code starts below this comment
    for (int i  = 0; Prefix != '\0' ; i++)
        {
        if(Prefix >= 'a' && Prefix <= 'z')
                {
                    Prefix = Prefix - 32;
                }
        }
    // User code ends above this comment
}

int main() 
   {
   char str[] = "hmh00234";
    
   printf("String input: %s\n", str);
   PrefixToUpper(str);
   printf("String output: %s\n", str);
   }
 

 

Link to comment
Share on other sites

OK, if you are sure that the ladder code that you've shown me is being executed, then I have no idea why it doesn't work.

I could debug it better if I had the project.

You can also debug it by putting in increment after the PrefixToUpper, so you can see with Online debug (or with HMI element) that the number is being incremented (and it should increment only once). You can also store Prefix Tractor Serial No into another string tag, so you could see its value after the function was called.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.