Navigation

    REXYGEN Community Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Initialization of string in REXLANG

    REXYGEN Studio
    3
    4
    552
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Scoobsalamander last edited by Scoobsalamander

      I got this warning in the Compiler Window but everything is working fine :

      "Warning compiling file 'WasteSrcfile.c' (line 30): variable 'stringTemp' is used without initialization"
      

      The initialization was one like this :

      char stringTemp[80];
      

      Something like this, to initialize an empty string will not work :

      char stringTemp[80] = "";
      R 1 Reply Last reply Reply Quote 0
      • R
        reitinge @Scoobsalamander last edited by

        @scoobsalamander
        Hi, you can divide the initialization into two commands:

        char stringTemp[80];
        stringTemp = "";
        

        if you want to be sure that the array is empty. The warning will disappear.

        Cheers,
        Jan

        S 1 Reply Last reply Reply Quote 0
        • S
          Scoobsalamander @reitinge last edited by Scoobsalamander

          @reitinge I did try this before but then I can't even compile due to an error.

          23345552-af28-4c1c-b9d1-6a4c22f5c625-image.png

          But apparently it was because I did the initialization of this string inside the main routine.
          Bizarre that it is throwing a warning for the string 'stringTemp' and not for the long variable 'index'.
          Both are only used inside the main routine.

          This is the complete code which is now running without a warning :

          //assigning inputs to variables, these variables are READ-ONLY
          double input(0) inputGLAS; 
          double input(1) inputGFT; 
          double input(2) inputPMD;
          double input(3) inputRA;
          double input(4) inputTEXT;
          double input(5) inputP_K;
          
          
          
          //assigning variables to outputs, these variables are WRITE-ONLY
          string output(0) stringOUT; //value to send to y0 output
          char stringTemp[80];
          
          
          
          //the init procedure is executed once when the REXLANG function block initializes
          long init(void)
          {
          	
          	return 0;
          }
          
          //the main procedure is executed repeatedly (once in each sampling period)
          long main(void)
          {
          	
          	
          	long index = 0;
          	
          	//char stringTemp[80];
                  stringTemp="";
          
          	strcat(stringTemp,"Vergeet+niet+volgend+vuilnis+buiten+te+zetten+:+");
          	
          	if (inputGLAS!=0)
          	{
          		strcat(stringTemp,"Glas");
          		index=index+1;
          	}
          	
          	if (inputGFT!=0)
          	{
          		if (index!=0)
          		{
          			strcat(stringTemp,",+");
          		}
          		strcat(stringTemp,"GFT");
          		index=index+1;
          	}
          	
          	if (inputPMD!=0)
          	{
          		if (index!=0)
          		{
          			strcat(stringTemp,",+");
          		}
          		strcat(stringTemp,"PMD");
          		index=index+1;
          	}
          	
          	if (inputRA!=0)
          	{
          		if (index!=0)
          		{
          			strcat(stringTemp,",+");
          		}
          		strcat(stringTemp,"Restafval");
          		index=index+1;
          	}
          	
          	if (inputTEXT!=0)
          	{
          		if (index!=0)
          		{
          			strcat(stringTemp,",+");
          		}
          		strcat(stringTemp,"Textiel");
          		index=index+1;
          	}
          	
          	if (inputP_K!=0)
          	{
          		if (index!=0)
          		{
          			strcat(stringTemp,",+");
          		}
          		strcat(stringTemp,"Papier+en+Karton");
          	}
          	
          
          	stringOUT=stringTemp;
          	return 0;
          }
          
          //the exit procedure is executed once when the task is correctly terminated
          // (system shutdown, downloading new control algorithm, etc.)
          long exit(void)
          {
          	/* PUT YOUR CODE HERE */
          	return 0;
          }
          
          1 Reply Last reply Reply Quote 0
          • Bradly999
            Bradly999 Banned last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            This is a community forum for REXYGEN users and fans. Detailed information can be found at REXYGEN homepage.

            There is also an outdated REXYGEN community forum.

            Powered by NodeBB.