College student, also an undergrad research assistant at NOAA's National Severe Storms Laboratory
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: MyndFyre[vL] on October 29, 2007, 04:40 PM
The reason I did that is because strcmp is null-terminated (strncmp would have been another choice).
Using == is not the proper way to compare char[] in C. The string literal "TAG" will always be in a static place in memory, as opposed to what he's reading from disk. == will compare the memory locations for equality (unless he's using an STL std::string or MFC CString), which would only return true if they're the same reference, which we know they're not.
By doing it the way I suggested, he's able to use a standard library string compare function, we're sure that it's going to not run into any unchecked-input security issues, and he avoids the interned-string issue.
To respond to your other questions, the reason the header is "returning" "TAGGet Up, Stand Up" is because there isn't a null terminator at the end of "TAG" (as someone else already pointed out). You could do a binary compare as well, but it's kind of awkward since it's only three bytes, which is why I opted for the copy-and-strcmp.
Quote from: ♥ on April 01, 2007, 03:28 PMQuote from: Zorm on April 01, 2007, 02:45 PM
By 'sketched out' I mean that it might be something other than a sensor malfunctioning... We had two fire alarms last night and two the night before so...
Are you serious? Your first thought was actually "sensor malfunction"? lol. Welcome to the dorms, where you have no peace and quiet, and will not get good sleep.
Quote from: Shout on February 14, 2007, 10:22 PM
I did it. In June I go to boot camp. Woot?
Page created in 0.231 seconds with 16 queries.