Can't fix this error, please help.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't fix this error, please help.

ArTicMyth
Reply | Threaded
Open this post in threaded view
|

Re: Can't fix this error, please help.

siko1056
On 12/31/19 11:42 AM, ArTicMyth wrote:
> Hey guys, i can't seem to fix this error and i was hoping one of you could
> help me :D
> (It shows the error when i choose the second option)
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled.png>
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled1.png>
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled2.png>
>
>

Please do not send only screenshots of your code.  The important lines are

   x = input ("Input: ", "s");
   if (x == "something")
     disp ("something")
   else
     disp ("else")
   endif

which result for the input "blub" in the following error:

   error: blub: mx_el_eq: nonconformant arguments (op1 is 1x4, op2 is 1x9)
   error: called from
    buggy at line 2 column 1


The solution is to use `strcmp()` [1] for string comparisons.  Octave
treats your input `x` as array of char (like C) and not as some string
class (like C++).

   x = input ("Input: ", "s");
   if strcmp (x, "something")
     disp ("something")
   else
     disp ("else")
   endif

HTH,
Kai


[1] https://octave.org/doc/v5.1.0/XREFstrcmp.html


Reply | Threaded
Open this post in threaded view
|

Re: Can't fix this error, please help.

ArTicMyth
Thank you this completely fixed the issue :D!



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html