why is this strcmp not working?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: why is this strcmp not working?

Post by afanofosc »

I mislead you, it appears. You need this file:

http://sourceforge.net/projects/bricxcc ... z/download

I will fix the links on the NBC download page. This reminds me that I am way super extremely late in producing an official release of 1.2.1.r5 and BricxCC 3.3.8.10. I will try to remedy that this week.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: why is this strcmp not working?

Post by afanofosc »

NXC does not currently support pointers so stdlib API functions that I have implemented are usually not exactly C stdlib. They often have slightly or significantly different parameter types. In NXC where you might normally use "char *" you would use the "string" type which is essentially identical to a character array, i.e., char msg[] = "123"; and where you might subsequently pass msg as a char * parameter you pass it either by value using a not exactly C syntax for array passing, i.e., void foo(char msg[]). or you use the string type instead, i.e., void foo(string msg). A char array is not necessarily null terminated but functions which use the string type expect that it is null terminated, i.e., strlen(msg) = 3 but ArrayLen(msg) = 4.

NXC supports structures but not structures with member functions and the string type is not a structure or a class. It is a char array which is expected to always be null terminated. You can treat it like a char array if you like as NXC is not particularly type safe when it comes to arrays and strings. Technically, a string is actually a byte array but it is sometimes useful to think of it like the char* or char array types in C.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
brothman01
Posts: 20
Joined: 16 Feb 2012, 22:59

Re: why is this strcmp not working?

Post by brothman01 »

Ahh yes, this link perfect, thank you for that link and that explanation of strings. That cleared up a lot of confusion. The update process seems like I just replace the old file with name "xxxxx" with it's new file with the same name "xxxxx"... but I am still getting error 1 when I try to compile that code you gave me earlier in this thread, when we first realized that I had an old version of the compiler...
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: why is this strcmp not working?

Post by afanofosc »

I don't understand what you mean by Error 1. Can you post a zip containing the code in a .nxc file plus all of the compiler output in a .txt file?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
brothman01
Posts: 20
Joined: 16 Feb 2012, 22:59

Re: why is this strcmp not working?

Post by brothman01 »

sure.. the code (which you already have because you actually made) is

Code: Select all

task main()
{
  string input = "fooba";
   int cmdComp = strcmp(input, "foobar");
   NumOut(0, LCD_LINE2, cmdComp);
   if (cmdComp == 0) {
     TextOut(0, LCD_LINE1, "cmdComp==0");
     Wait(1000);
   } else {
     TextOut(0, LCD_LINE1, "cmdComp!=0");
    Wait(1000);
   }
   while(true);
}
and as for compiler output, there is none that I'm aware of. Before I remember an AppleScript dialog used to pop up with any errors and debug info, with buttons on the bottom marked "edit" and "ok" but now that dialog just says Error 1 has occured, while still giving me the option to edit or press ok...

Oh, and this error is not specific to this code. I've tried it with other .nxc docs and I get error 1 with those too.. maybe I have a virus or something? In any case, the .zip is attached, but there is only a BBedit code file.. there is no debugging output from AS, and I could not find an error log in Console for NXC.. was there one that I missed or if not, what else should I do?
Attachments
NXC Stuff.zip
(1.61 KiB) Downloaded 254 times
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: why is this strcmp not working?

Post by afanofosc »

I recommend that you consider trying out my NXTCC utility for Mac OS X. It includes an integrated NBC compiler and simple code editor along with all the standard tool windows that come with BricxCC. http://bricxcc.sourceforge.net/utilities.html

Your nxc file is not a plain ASCII file. Probably something to do with the editor you are using. I see 0xCA characters in it that in notepad look like a capital E with a ^ on top. These are what are causing the compiler to fail.

I would not recommend using the AppleScript files anymore. They have not been updated in quite a while. It would be better to use some sort of plugin for an editor like xcode or textmate (google "nxc textmate" or "nxc xcode").

http://www.mastincrosbie.com/Marks_LEGO ... _10.5.html

You could also run the compiler from a Terminal window prompt. Or you could use my NXTCC tool. My Mac OS X tools require that you have the LEGO MINDSTORMS FANTOM drivers installed for Mac OS X.

http://cache.lego.com/upload/contentTem ... 5DA785.zip

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
brothman01
Posts: 20
Joined: 16 Feb 2012, 22:59

Re: why is this strcmp not working?

Post by brothman01 »

I recommend that you consider trying out my NXTCC utility for Mac OS X. It includes an integrated NBC compiler and simple code editor along with all the standard tool windows that come with BricxCC.
well, I know it's not what you said, but I do use the NeXT Tools (first on the page) and love it. Is it written in java? Anyway, I was looking at the page again, and I didn't see the NXTCC util, but didit mean the tools thing that I use?
Your nxc file is not a plain ASCII file. Probably something to do with the editor you are using. I see 0xCA characters in it that in notepad look like a capital E with a ^ on top. These are what are causing the compiler to fail.
Wow, you were right, lol.. I hate when that happens! Now it compiles no problem.
I would not recommend using the AppleScript files anymore. They have not been updated in quite a while. It would be better to use some sort of plugin for an editor like xcode or textmate (google "nxc textmate" or "nxc xcode").
I've been using BBedit to write the code, and the AS things to compile, but when I first got nbc, I was using the terminal command to compile + upload, so I can just do that again.
They have not been updated in quite a while. It would be better to use some sort of plugin for an editor like xcode or textmate (google "nxc textmate" or "nxc xcode").
I do see ur point, but I used the xcode plugin before (probably partly incorrectly) and I didn't notice too many advantages... but like I said, I think I used it wrong.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: why is this strcmp not working?

Post by afanofosc »

NXTCC is right below the NeXT Tools link. Here's the direct link:

http://bricxcc.sourceforge.net/nxtcc_osx.zip

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
brothman01
Posts: 20
Joined: 16 Feb 2012, 22:59

Re: why is this strcmp not working?

Post by brothman01 »

Woah, thanks a lot, I don't know how I missed that! this version is similar to the one I used, but is better in a lot of ways :D

Man, I'm tired... Thanks again though, and I'm sure I'll be back pretty soon with another question. You've helped me with a lot of different things in the NXC, I won't try to guess how useful my student-education of computers is, but in the future, if you ever need something that doesn't require great technical expertise done, I volunteer. (like maintaining the NXC non-forum part of the site or something maybe? Or any java work (I do A LOT of java) really whatever work you need done) Thanks again.
brothman01
Posts: 20
Joined: 16 Feb 2012, 22:59

Re: why is this strcmp not working?

Post by brothman01 »

I don't mean, "I want this, do it now!" (even though that is what it seems like)
I just meant that if you ever need or want any assistance.. I don't want to feel like I was pressuring or anything..
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests