Example #1
0
bool OpenDevice(char *theName, int *theDevice)
{
	if (compareStr(theName, "com1"))
		*theDevice = 1;
	else if (compareStr(theName, "com2"))
		*theDevice = 2;
	else
	{
		*theDevice = 0;
		return false;
	}

	return true;
}
int main(int argc, char **argv)
{
	if (argc != 2)
	{
		printf("Next time, you must pass a password as an argument. Program terminating...\n");
		return 0;
	}

	char *actualPassword = argv[1], enteredPassword[100000];
	printf("Enter password:"******"%[^\n]%*c", enteredPassword);

	int tryCount = 3;
	while (!compareStr(actualPassword, enteredPassword))
	{
		if (tryCount <= 0)
		{
			printf("All passwords you entered were wrong. Program terminating...\n");
			return 0; 
		}
		printf("Try again (%i):", tryCount);
		scanf("%[^\n]%*c", enteredPassword);
		tryCount--;
	}

	printf("Correct password!\n");
	return 0;
}
int compareIntInStr(int int1,int int2){
	int length1 = getLength(int1);
	int length2 = getLength(int2);
	char* char1 = (char*)malloc(length1*sizeof(char));
	char* char2 = (char*)malloc(length2*sizeof(char));
	sprintf(char1,"%d",int1);
	sprintf(char2,"%d",int2);
	return compareStr(char1,length1,char2,length2);
}
Example #4
0
/**
 * Match pattern and str. Pattern is in format UPPERCASElowercase
 * @param pattern
 * @param pattern_len
 * @param str
 * @param str_len
 * @return 
 */
scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) {
    int pattern_sep_pos_short;

    if (pattern[pattern_len - 1] == '#') {
        size_t new_pattern_len = pattern_len - 1;

        pattern_sep_pos_short = patternSeparatorShortPos(pattern, new_pattern_len);

        return compareStrAndNum(pattern, new_pattern_len, str, str_len, num) ||
                compareStrAndNum(pattern, pattern_sep_pos_short, str, str_len, num);
    } else {

        pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len);

        return compareStr(pattern, pattern_len, str, str_len) ||
                compareStr(pattern, pattern_sep_pos_short, str, str_len);
    }
}
Example #5
0
/**
 * Convert string describing unit to its representation
 * @param units units patterns
 * @param unit text representation of unknown unit
 * @param len length of text representation
 * @return pointer of related unit definition or NULL
 */
const scpi_unit_def_t * SCPIParser::translateUnit(const scpi_unit_def_t * units, const char * unit, size_t len) {
    int i;

    if (units == NULL) {
        return NULL;
    }

    for (i = 0; units[i].name != NULL; i++) {
        if (compareStr(unit, len, units[i].name, strlen(units[i].name))) {
            return &units[i];
        }
    }

    return NULL;
}
Example #6
0
static void test_compareStr() {

    CU_ASSERT_TRUE(compareStr("abcd", 1, "afgh", 1));
    CU_ASSERT_TRUE(compareStr("ABCD", 4, "abcd", 4));
    CU_ASSERT_TRUE(compareStr("AbCd", 3, "AbCE", 3));
    CU_ASSERT_TRUE(compareStr("ABCD", 1, "a", 1));

    CU_ASSERT_FALSE(compareStr("abcd", 1, "efgh", 1));
    CU_ASSERT_FALSE(compareStr("ABCD", 4, "abcd", 3));
}
Example #7
0
int findStrNode(SLIST *strList, struct String *src)
{
	int retval = -1;
	int cmp;
	strList->cur = strList->head;
	while (strList->cur != NULL)
	{
		cmp = compareStr(strList->cur->str, src);
		//cmp = findLocStr(strList->cur->str, src, 0);
		//Found string
		if (cmp == 0)
		{
			retval = 0;
			break;
		}
		else
			strList->cur = strList->cur->next;
	}
	return retval;
}
Example #8
0
void ind_sortHoarArray(int l, int r)
{
    indDBase c;
    long base, opposite, p;
    base = l;
    opposite = r;
    while (base != opposite) {
        if ( compareStr(indDBArrayElem[base].key->bdate,
                indDBArrayElem[opposite].key->bdate) ^ (base > opposite) ) {
            c = indDBArrayElem[base];
            indDBArrayElem[base] = indDBArrayElem[opposite];
            indDBArrayElem[opposite] = c;
            p = base;
            base = opposite;
            if (p < opposite) opposite = p + 1;
            else opposite = p - 1;
        } else {
            if (base < opposite) opposite--;
            else opposite++;
        }
    }
    if (l < base-1) ind_sortHoarArray(l, base-1);
    if (base+1 < r) ind_sortHoarArray(base+1, r);
}
Example #9
0
/**
 * Match pattern and str. Pattern is in format UPPERCASElowercase
 * @param pattern
 * @param pattern_len
 * @param str
 * @param str_len
 * @return 
 */
bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) {
    int pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len);
    return compareStr(pattern, pattern_len, str, str_len) ||
            compareStr(pattern, pattern_sep_pos_short, str, str_len);
}
Example #10
0
void addNode(SLIST *strList, SNODE *node)
{
	SNODE *prevNode;
	//Add node to empty list
	if (strList->length == 0)
	{
		strList->head = node;
		strList->tail = node;
		strList->length++;
	}
	//non-empty list
	else
	{
		//new node should appear alphabetically before strList->head
		if (compareStr(node->str, strList->head->str) == -1)
		{
			addToFront(strList, node);
		}
		//new node is equal to strList->head
		else if (compareStr(node->str, strList->head->str) == 0)
			strList->head->count++;
			
		//node should appear alphabetically after strList->tail
		else if ((compareStr(node->str, strList->tail->str)) == 1)
		{
			addToBack(strList, node);
		}
		//new node is equal to strList->tail
		else if (compareStr(node->str, strList->tail->str) == 0)
			strList->tail->count++;
		//new node is not smaller than strList->head nor greater than strList->tail
		else
		{
			//Start at node after head
			strList->cur = strList->head;
			while (strList->cur != NULL)
			{
				//new node contains the same string as strList->cur
				if (compareStr(node->str, strList->cur->str) == 0)
				{
					strList->cur->count++;
					break;
				}			
				//node->str should appear alphabetically after cur->str
				else if (compareStr(node->str, strList->cur->str) == 1)
				{
					strList->cur = strList->cur->next;					
				}
				//node->str should appear alphabetically before cur->str
				else
				{
					prevNode = strList->cur->prev;
					//First have node point to forwards to current and backwards to previous node
					node->next = strList->cur;
					node->prev = prevNode;
					prevNode->next = node; //Point old previous node to new node
					strList->cur->prev = node;
					strList->length++;
					break;
				}
			}
		}
	}
}