Exemplo n.º 1
0
// STRING_FUNC
int string_func::concatStr(char *pOriginS, char *pAdditStr)
{
	int iAdditLen = getStrLen(pAdditStr);

	for (int i = getStrLen(pOriginS) - 1, k = 0; k < iAdditLen; k++, i++) pOriginS[i] = pAdditStr[k];

	return 0;
}
Exemplo n.º 2
0
bool string_func::isSameStr(char *p1, char *p2)
{
	if (getStrLen(p1) == getStrLen(p2)) {

		for (int i = 0; p1[i] && p2[i]; i++)
		{
			if (p1[i] != p2[i]) return false;
		}
		
		return true;
	}
	else
		return false;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
	/*
	printf("Argument count: %d\n", argc);
	for (int i = 0; i < argc; i++) {
		printf("Argument vector values:%s at %p memory\n", argv[i], argv[i]);
		for (char *j=argv[i]; *j!='\0'; j++) {
			printf("Another way to print argument vector values: "
                               "%c at %p memory\n", *j, j);
		}
	}
	*/

	char *inputStrPtr = argv[1];
	if (inputStrPtr == NULL) {
		printf("No Input String specified\n");
		exit(1);
	}
	printf("Input String: %s\n", inputStrPtr);

	int inputStrLen = 0;
	inputStrLen = getStrLen(inputStrPtr);
	printf("Input String Length: %d\n", inputStrLen);

        int flagArray[256] = {};
	for (int index = 0; index < 256; index++) {
		printf("%d,",flagArray[index]);
	}
	printf("\n");

	int strRepChar = 0;
	int algoCount = 0;
        for (char *inputCharPtr = inputStrPtr; *inputCharPtr != '\0'; inputCharPtr++){
		algoCount++;
		if (inputStrLen > 256) {
			printf("Input string length > 256. String can't have unique chars\n");
			strRepChar = 1;
			break;
		}

		int index = *inputCharPtr;
		if (flagArray[index] > 0) {
			printf("Matching characters found. String doesnt have unique characters\n");
			strRepChar = 1;
			break;
		}
		else {
			flagArray[index] = 1;
		}
	}
	if (strRepChar != 1) {
		printf("No matching characters found. String has unique characters\n");
	}

	for (int index = 0; index < 256; index++) {
		printf("%d,",flagArray[index]);
	}
	printf("\n");
	printf("Algorithm Complexity is O(n) or count %d\n", algoCount);
	return 0;
}
Exemplo n.º 4
0
int findGetParams(char* url) {
    int len = getStrLen((const char*)url);
    
    for (int i = 0; i < len; ++i) {
        if (url[i] == '?') {
            url[i] = '\0';
            len = i;
            break;
        }
    }
    return len;
}
Exemplo n.º 5
0
int sendData(struct requestValues* reqValues) {
    if (reqValues == NULL) {
        perror("pointer");
        return -1;
    }
    
    struct responseValues respValues;
    char path[PATH_LEN + 1] = {};
    beforeSend(reqValues, &respValues, path);
    
    char resp[RESP_HEADERS_BUF_SIZE + 1] = {};
    
    setRespHeaders(&respValues, resp);
    addSymbs(resp, "\r\n\r\n");
    sendAll(reqValues->sockfd, resp, getStrLen(resp));
    
    if (path[0] != '\0') {
        int src = open((const char*)path, O_RDONLY);
        off_t offset = 0;
        sendfile(reqValues->sockfd, src, &offset, respValues.contLen);
        close(src);
    }
    return 0;
}
Exemplo n.º 6
0
void printWords(char** words, int numWords)
{
	//printf("numWords: %d\n", numWords);
	int i;
	for(i = 0; i < numWords; i++)
	{
		char* word = words[i];
		int length = getStrLen(word);
		//printf("printWord1");
		//printWord(word);
		//printf("printWord2");
		//int length = strlen(word);
		int j;
		//printf("length: %d\n", length);
		for(j = 0; j < length; j++)
		{
			char c = word[j];
			
			printf("%c", c);
		}
		printf(" ");
	}
	printf("\n");
}