static void testStringCompare(void) { test(stringCompare("cat", "cat"), 0); test(stringCompare("cat", "dog"), -1); test(stringCompare("dog", "cat"), +1); test(stringCompare("", "xxx"), -1); test(stringCompare("xxx", ""), +1); }
bool Term::equals(const Term* o) const { //Func - Compares two terms, returning true if they have the same // field and text. //Pre - o is NULL or o points to a Term //Post - if pre(o) is NULL then false is returned, otherwise the result // of the comparison has been returned which can be true or false //Check if o points to a term if (o == NULL){ return false; } //compare field with field of o and text with text of o and return the result of the comparisons return stringCompare(field,o->field) == stringCompare(text,o->text) == 0; }
int main() { //Get user's input. printf("Please input the first string. No more than 20 characters.\n"); char input1[21]; gets_s(input1, 20); printf("Please input the second string. No more than 20 characters.\n"); char input2[21]; gets_s(input2, 20); //Foreach the string. int i; int compareReturn = 0; int breakCount = 0; for (i = 0; i < 21; i++) { compareReturn = stringCompare(input1[i], input2[i]); //Judge the return of the function. When it is 1, make breakCount varible plus 1. if (compareReturn == 1) { breakCount++; } } //Use breakCount varible to judge these two strings are totally same or not. if (breakCount == 0) { printf("These two strings are same.\n"); } else printf("These two strings are different.\n"); return 0; }
bool DMString::operator ==(DMString& dm_string) { if (this->max_length != dm_string.max_length) { return false; } bool isSame = stringCompare(this->char_string, dm_string.char_string, this->max_length); return isSame; }
void MouseListener::handleEvent(const MinVR::EventRef& event, double synchronizedTime) { if (startsWith(event->getName(), "mouse_", 6)) { if (event->getName() == "mouse_scroll") { handleClick(MouseButton::SCROLL, event->get2DData().y > 0, event->get2DData()); return; } MinVR::WindowRef window = event->getWindow(); glm::dvec2 res(window->getWidth(), window->getHeight()); glm::dvec2 pos = event->get2DData() / res; if (event->getName() == "mouse_pointer") { handleMove(pos); } else { MouseButton button; if (stringCompare(event->getName(), "left", 10, 4)) { button = LEFT; } else if (stringCompare(event->getName(), "middle", 10, 6)) { button = MIDDLE; } else if (stringCompare(event->getName(), "right", 10, 5)) { button = RIGHT; } if (stringCompare(event->getName(), "up", event->getName().size()-2, 2)) { handleClick(button, false, pos); } else { handleClick(button, true, pos); } } } }
#include "CLucene/StdHeader.h" #include "Document.h" #include "Field.h" #include "CLucene/util/StringBuffer.h" using namespace std; using namespace lucene::util; namespace lucene{ namespace document{ DocumentFieldList::DocumentFieldList(Field* f, DocumentFieldList* n) { //Func - Constructor //Pre - f != NULL // n may be NULL //Post - Instance has been created CND_PRECONDITION(f != NULL, "f is NULL") field = f; next = n; } DocumentFieldList::~DocumentFieldList(){ //Func - Destructor //Pre - true //Post - Instance has been destroyed _DELETE(next); _DELETE(field); } DocumentFieldEnumeration::DocumentFieldEnumeration(const DocumentFieldList* fl){ //Func - Constructor //Pre - fl may be NULL //Post - Instance has been created fields = fl; } DocumentFieldEnumeration::~DocumentFieldEnumeration(){ //Func - Destructor //Pre - true //Post - Instance has been destroyed } bool DocumentFieldEnumeration::hasMoreElements() const { return fields == NULL ? false : true; } Field* DocumentFieldEnumeration::nextElement() { //Func - Return the next element in the enumeration //Pre - true //Post - The next element is returned or NULL Field* result = NULL; //Check if fields is still valid if (fields){ result = fields->field; fields = fields->next; } return result; } Document::Document(){ //Func - Constructor //Pre - true //Post - Instance has been created fieldList = NULL; } Document::~Document(){ //Func - Destructor //Pre - true //Post - Instance has been destroyed _DELETE(fieldList); } // Adds a field to a document. Several fields may be added with // the same name. In this case, if the fields are indexed, their text is // treated as though appended for the purposes of search. */ void Document::add(Field& field) { fieldList = new DocumentFieldList(&field, fieldList); } // Returns a field with the given name if any exist in this document, or // null. If multiple fields may exist with this name, this method returns the // last added such added. */ bool Document::getField(const char_t* name, Field*& retField) { for (DocumentFieldList* list = fieldList; list != NULL; list = list->next) if ( stringCompare(list->field->Name(), name) == 0 ){ retField = list->field; return true; } return false; }
bool DMString::operator==(const char * char_string) { int targetLength = getLength((char *) char_string); if (this->max_length != targetLength) { return false; } bool isSame = stringCompare(this->char_string, (char *) char_string, this->max_length); return isSame; }
int (*getfn(const char *word))() { struct table_entry* p; for (p = cmds; p->cmd; ++p) { if (!stringCompare(word, p->cmdname)) { return p->cmd; } } wprintf(&shell_wnd, "Command not found\n"); return nothingcommand; }
void testStringCompare() { if(stringCompare("cat","cat") == 0) { wprintf(&shell_wnd, "strings same pass\n"); } else { wprintf(&shell_wnd, "strings same fail\n"); } if(stringCompare("cate","cat") == -1) { wprintf(&shell_wnd, "strings diff pass\n"); } else { wprintf(&shell_wnd, "strings diff fail\n"); } }
int isEqual(char **original,char **expected,int range) { int i; for(i=0; i<range; i++) { if(!stringCompare(original[i],expected[i])) return 0; } return 1; }
int main(){ char c1[20],c2[20]; gets(c1); gets(c2); if(stringCompare(c1,c2)==1){ printf("Strings Match\n"); } else{ printf("Strings DO NOT Match\n"); } }
/** Prints a user-readable version of this query. */ const char_t* TermQuery::toString(const char_t* field) { lucene::util::StringBuffer buffer; if ( stringCompare(term->Field(),field)!= 0 ) { buffer.append(term->Field()); buffer.append(_T(":")); } buffer.append(term->Text()); if (boost != 1.0f) { buffer.append(_T("^")); buffer.append( boost,10 ); } return buffer.ToString(); }
static bool _predicate (void) { bool fnval; Torture in, out; in.int8 = 0; in.uint8 = 1; in.int16 = 2; in.uint16 = 3; in.int32 = 4; in.uint32 = 5; in.int64 = 6; in.uint64 = 7; // in.float32 = 3.14; // in.float64 = 3.1415; // in.bool = false; in.int8Ptr = &in.int8; // Not technically legal to point into struct. in.tuple = stringAllocateInitialize("Hello, world!"); strcpy ((char *) in.array, helloWorld); uint8_t buf[sizeof (Torture) + refSize(in.tuple)]; EtnBufferEncoder *e = etnBufferEncoderNew(buf, sizeof(buf)); EtnLength etnEncodedSize; etnEncode((EtnEncoder *) e, EtnToValue(&TortureType, &in), &etnEncodedSize); EtnBufferDecoder *d = etnBufferDecoderNew(buf, etnEncodedSize); etnDecode((EtnDecoder *) d, EtnToValue(&TortureType, &out)); fnval = in.int8 == out.int8 && in.uint8 == out.uint8 && in.uint16 == out.uint16 && in.uint16 == out.uint16 && in.uint32 == out.uint32 && in.uint32 == out.uint32 && in.uint64 == out.uint64 && in.uint64 == out.uint64 // && in.float32 == out.float32 // && in.float64 == out.float64 // && in.bool == out.bool && *in.int8Ptr == *out.int8Ptr && ! stringCompare (in.tuple, out.tuple) && ! strcmp ((char *) out.array, helloWorld); free (e); etnBufferDecoderFree (d); stringUnhook (&in.tuple); stringUnhook (&out.tuple); return fnval; }
void stringSort(char str[][50]){ int start = 0, end = 9, i = 0; char temp[50] = {'\0'}; for(start = 0; start < end; end--){ for(i = 0; i < end; i++){ if(stringCompare(str[i], str[i+1]) == 1){ strcpy(temp, str[i]); strcpy(str[i], str[i+1]); strcpy(str[i+1], temp); } } } }
struct transaction * sortedArraysCommonElements(struct transaction *A, int ALen, struct transaction *B, int BLen) { if (A == NULL || B == NULL) return NULL; struct transaction* result = NULL; int i; int count = 0; for (i = 0; i < ALen; i++) { int j; for (j = 0; j < BLen; j++) { if (stringCompare(A[i].date, B[i].date)) { count++; struct transaction *temp = result; result = (struct transaction*)malloc(count*sizeof(struct transaction)); int z, k; //increasing the array size dynamically for (z = 0; z < count - 1; z++) { result[z].amount = temp[z].amount; k = -1; do{ k++; result[z].date[k] = temp[z].date[k]; } while (result[z].date[k] != '\0'); k = -1; do{ k++; result[z].description[k] = temp[z].description[k]; } while (result[z].date[k] != '\0'); } //copying the new transaction result[count - 1].amount = A[i].amount; k = -1; do{ k++; result[count - 1].date[k] = A[i].date[k]; } while (result[count - 1].date[k] != '\0'); k = -1; do{ k++; result[count - 1].description[k] = A[i].description[k]; } while (result[count - 1].date[k] != '\0'); break; } } } return result; }
static bool _predicate (void) { bool fnval; Strings in1, out1; StructContainingTuple in2, out2; in1.field1 = stringAllocateInitialize("Hello, world!"); in1.field2 = stringAllocateInitialize("Goodbye, cruel world!"); in2.strings = stringAllocateEmpty(sizeof (Strings)); stringConcat (in2.strings, &in1, sizeof (Strings)); uint8_t buf[1024]; EtnBufferEncoder *e = etnBufferEncoderNew(buf, sizeof(buf)); EtnLength etnEncodedSize; etnEncode((EtnEncoder *) e, EtnToValue(&StructContainingTupleType, &in2), &etnEncodedSize); EtnBufferDecoder *d = etnBufferDecoderNew(buf, etnEncodedSize); etnDecode((EtnDecoder *) d, EtnToValue(&StructContainingTupleType, &out2)); out1 = *(Strings *) out2.strings->ptr; fnval = ! stringCompare (in1.field1, out1.field1) && ! stringCompare (in1.field2, out1.field2); free (e); etnBufferDecoderFree (d); stringUnhook (&in1.field1); stringUnhook (&in1.field2); stringUnhook (&in2.strings); stringUnhook (&out1.field1); stringUnhook (&out1.field2); stringUnhook (&out2.strings); return fnval; }
int main() { char str1[100],str2[100]; int compare; printf("Enter first string: "); scanf("%s",str1); printf("Enter second string: "); scanf("%s",str2); compare = stringCompare(str1,str2); if(compare == 1) printf("Both strings are equal."); else printf("Both strings are not equal"); return 0; }
NFAPI SCCString gh_getZipPackURL(SCCString url) { // https://github.com/qokelate/CCGame // https://github.com/qokelate/CCGame.git // https://codeload.github.com/liftoff/GateOne/zip/master if (false == stringHasSubString(url, ".github.com/") && false == stringHasSubString(url, "://github.com/")) return nullptr; if (stringHasSuffix(url, "/zip/master")) { auto ptr = copyAsSCString(url); MLog("url: ", ptr); return ptr; } auto len = SCStringLen(url); auto ptr = (SCString)SCAlloc(len + 100); strcpy(ptr, "https://codeload.github.com"); regexMatchFirst((void *)url, len, "://[^/]+/", nullptr, [&](SCRegexErrorInfo *errorInfo, size_t index, byte *buffer, size_t dataSize, void *param) { if (errorInfo) { MLog("error: ", errorInfo->errorMessage); return false; } auto pp = (SCCString)buffer + dataSize - 1; strcat(ptr, pp); return true; }); len = SCStringLen(ptr); { auto pp = ptr + len - 4; if (stringCompare(pp, ".git")) *pp = 0; } strcat(ptr, "/zip/master"); MLog("url: ", ptr); return ptr; }
int countGreaterNumbers(struct transaction *Arr, int len, char *date) { int i = 0, c = -1; if (date != NULL && len > 0 && Arr != NULL){ for (i = 0; i < len; i++) { if (stringCompare(Arr[i].date, date)) c = i; } if (c != -1) return len - c - 1; else return 0; } else return -1; }
// ----------------------------------- // Main function // Arguments: argc = number of arguments suppled by user // argv = array of argument values // // int main( int argc, char** argv ) { int done; char input[255]; command_t temp_command; char tempPath[255]; //if statements for signal handling if (signal(SIGCHLD, sig_child_handler) == SIG_ERR) { perror("Unable to create new SIGCHLD signal handler!"); exit(-1); } // //if statements for ctrl-c handling // if (signal(SIGINT, sig_int_handler) == SIG_ERR) { // perror("Unable to create new SIGCHLD signal handler!"); // exit(-1); // } done = FALSE; while (!done) { printf("$"); fflush(stdout); gets(input); parse(input, &temp_command); if (stringCompare(temp_command.name,"exit")==1) { done = TRUE; } else if (is_builtin(&temp_command)) { do_builtin(&temp_command); } else if (find_fullpath(tempPath, &temp_command)) { execute(&temp_command); } else { printf("Command not found.\n"); } cleanup(&temp_command); } // printf( "CSCI 340 Homework Assignment 2 - Have Fun!\n" ); return 0; } // end main function
byte parseCommand( char *message, byte length, byte *position, command_t **command) { byte errorCode = 5; for (byte commandType = 0; commandType < commandCount; commandType ++) { *command = & commands[commandType]; if (stringCompare((*command)->name, & message[*position])) { skipToken(message, length, position); errorCode = 0; break; } } return(errorCode); }
int main() { // Declare 2dimensions arrays and initialing... char input[2][21] = {}; int returnValue; // Get the two strings and estimate each length... printf("Please input the first string:"); gets(input[0]); printf("Please input the second string:"); gets(input[1]); //Give strings to the compare function... returnValue = stringCompare(input); //Print... if (returnValue < 0) printf("%s is smaller than %s.\n",input[0],input[1]); else if (returnValue == 0) printf("%s is equal to %s.\n",input[0],input[1]); else printf("%s is larger than %s.\n",input[0],input[1]); }
/** * Loads in the .WAL Image under the directory "Q2/textures/" * If the image already exists in the data array, then keep a pointer * to the already-loaded .WAL Image. * If the image does not already exist, load it in and store its name * in alphabetically-ordered array of texture names. */ void TextureLoader::loadNew( char *name, LPDIRECT3DDEVICE9 device ) { // Go through each image, testing to see if the image was already loaded for ( unsigned int imageNum = 0; imageNum < loadedImages.size(); ++imageNum ) { // Compare the WALImages' names. If they are the same, if ( stringCompare( name, loadedImages[ imageNum ]->getName() ) == 0 ) { // make a pointer to it in textures textures.push_back( loadedImages[ imageNum ] ); return; } } // If the image was not loaded previously, then load it in. // Load in the WAL image directly WALImage *temp = new WALImage(); temp->load( name, palette, 319, device ); loadedImages.push_back( temp ); textures.push_back( temp ); };
static bool _predicate (void) { Buffer buffer, out; buffer.buf = stringAllocateInitialize("0123456789"); buffer.current = &((uint8_t *) buffer.buf->ptr)[5]; uint8_t buf[1024]; EtnBufferEncoder *e = etnBufferEncoderNew(buf, sizeof(buf)); EtnLength etnEncodedSize; etnEncode((EtnEncoder *) e, EtnToValue(&BufferType, &buffer), &etnEncodedSize); EtnBufferDecoder *d = etnBufferDecoderNew(buf, etnEncodedSize); etnDecode((EtnDecoder *) d, EtnToValue(&BufferType, &out)); free (e); etnBufferDecoderFree (d); return ! stringCompare (buffer.buf, out.buf) && out.current == &((uint8_t *) buffer.buf->ptr)[5] && *out.current == '5'; }
/// string-ci>? euxlValue euxlstringCaInGt() { return (stringCompare('>', euxmTrue)); }
/// string-ci=? euxlValue euxlstringCaInEql() { return (stringCompare('=', euxmTrue)); }
/// string-ci<=? euxlValue euxlstringCaInLtEq() { return (stringCompare('L', euxmTrue)); }
/// string>? euxlValue euxlStringGt() { return (stringCompare('>', euxmFalse)); }
/// string=? euxlValue euxlStringEql() { return (stringCompare('=', euxmFalse)); }
/// string<=? euxlValue euxlStringLtEq() { return (stringCompare('L', euxmFalse)); }