/* * Splits the string into two using the given delimeter and outputs * result to both the variable out1 and out2. */ void stringSplit(char* s, char delimiter, char* out1, char* out2){ int i; int o = 0; for (i = 0; i < stringLength(s); i++) { if (s[i] == delimiter) { o = i+1; if (i != stringLength(s)) { out1[i]='\0'; } } if (!o){ out1[i] = s[i]; } else{ out2[i-o] = s[i]; } } if(!o){ out1[i] = '\0'; out2[0] = '\0'; } else{ out2[i-o] = '\0'; } return; }
bool endsWith(const char* str, const char* substr) { int len = stringLength(str); int len2 = stringLength(substr); if (len2 > len) return false; return equalStrings(str + len - len2, substr); }
/** * To extract the argument of address * * Input: * String the whole argument * * Return the value of the address * Throw if value is invalid */ int extractValue(String *arguments){ char *returnChar; int returnInt; String *string; stringTrimLeft(arguments); if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); if(stringCharAt(arguments,0) == ';' || stringLength(arguments) == 0) Throw(ERR_NO_ARGUMENT); string = stringRemoveWordNotContaining(arguments,",;"); stringTrim(string); if(stringLength(string) == 0) Throw(ERR_EMPTY_ARGUMENT); returnChar = stringSubstringInChar(string,0,string->length); returnInt = evaluate(returnChar); free(string); return returnInt; } //pass to jason
int substring(const char source[], int start, int count) { char result[count + 1]; int stringLength(const char string[]); int sourceLength = stringLength(source); int i; // What to do if the count is off the end of the string if (count > (sourceLength - 1)) // Would have subtracted 1 but need space for "null" character as well count = (sourceLength - start ); int j = 0; for(i = start; i <= count; ++i) { result[j] = source[i]; ++j; if (i == count) result[i] = '\0'; } for (i = 0; i < (stringLength(result)); ++i) printf("%c", result[i]); printf("\nDone\n"); return 0; }
void testInputCases() { int i,length1,length2; char *input; struct testcases { char *input1; char *input2; char *output; }test[5] = { {"saiseshu","seshugsaisss","seshu"},//input2>input1 {"azqpyzaz","zqpzqpyz","zqpyz"},//updating the result from zqp to zqpyz {"i am a good boy","am i good boy"," good boy"},//input1>input2 {"mmmwmmm","gsffswhshh","w"},//having chance to getting result f since input2 has ff as the part {"qwerty","asdfg",""}//no common substring }; for(i=0;i<5;i++) { length1=stringLength(test[i].input1); length2=stringLength(test[i].input2); input=stringManage(test[i].input1,'#',test[i].input2,'$',length1,length2); if(isEqual(getResult(input,length1,length2),test[i].output)) printf("pass\n"); else printf("fail\n",getResult(input,length1,length2)); } }
int main(void) { printf("%i ", stringLength("stringLenght test")); printf("%i ", stringLength("")); printf("%i\n", stringLength("complete")); return 0; }
int main(void) { int stringLength(const char *string); printf("%i, ", stringLength("stringLength test")); printf("%i, ", stringLength("")); printf("%i\n", stringLength("complete")); return 0; }
void JsonSerializer::serialize(const char* label, unsigned int value) { writeBlockComma(); char tmp[20]; writeString(label); toCString(value, tmp, 20); m_file.write(" : ", stringLength(" : ")); m_file.write(tmp, stringLength(tmp)); m_is_first_in_block = false; }
int main (void) { int stringLength (const char string[]); const char word1[] = { 'a', 's', 't', 'e', 'r', '\0' }; const char word2[] = { 'a', 't', '\0' }; const char word3[] = { 'a', 'w', 'e', '\0'}; printf ("%i %i %i\n", stringLength (word1), stringLength (word2), stringLength (word3)); return 0; }
/** * To extract the argument of access or banked * * Input: * String the whole argument * * Return the value of access/banked * Throw if value is invalid */ int extractAccessBanked(String *arguments){ char location; char *returnChar; int returnInt; String *string; String *banked = stringNew(textNew("BANKED")); //1 String *access = stringNew(textNew("ACCESS")); //0 if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); if(stringLength(arguments) == 0 ||stringCharAt(arguments,0) == ';') Throw(ERR_NO_ARGUMENT); stringTrimLeft(arguments); if(stringLength(arguments) == 0 ||stringCharAt(arguments,0) == ';') Throw(ERR_EMPTY_ARGUMENT); string = stringRemoveWordNotContaining(arguments,",;"); stringTrim(string); if(stringLength(string) == 0){ if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); Throw(ERR_EMPTY_ARGUMENT); } else if(stringLength(string) == 6){ if(stringIsEqual(string,banked)) returnInt = 1; else if(stringIsEqual(string,access)) returnInt = 0; else{ returnChar = stringSubstringInChar(string,0,string->length); returnInt = evaluate(returnChar); } } else{ returnChar = stringSubstringInChar(string,0,string->length); returnInt = evaluate(returnChar); } if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); free(string); return returnInt; }
END_TEST START_TEST(stringLengthTest) { #line 14 int i; i = stringLength("test"); fail_unless(i == 4, "did not return 4 for the word test"); fail_unless(stringLength("") == 0, "did not return 0 for empty string"); }
/* * Find the lengths of three strings. */ int main (void) { // String as an array char string1[] = "firstString"; // String as a pointer to array char *string2 = "secondString"; printf("Size of \"%s\" is %d\n", string1, stringLength(string1)); printf("Size of \"%s\" is %d\n", string2, stringLength(string2)); // Length of string literal printf("Size of \"%s\" is %d\n", "thirdString", stringLength("thirdString")); return EXIT_SUCCESS; }
/** * To extract the argument of location to save * * Input: * String the whole argument * * Return the value of the location * Throw if value is invalid */ int extractDestination(String *arguments){ char location; char *returnChar; int returnInt; String *string; if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); if(stringLength(arguments) == 0 ||stringCharAt(arguments,0) == ';') Throw(ERR_NO_ARGUMENT); stringTrimLeft(arguments); if(stringLength(arguments) == 0 || stringCharAt(arguments,0)== ';') Throw(ERR_EMPTY_ARGUMENT); string = stringRemoveWordNotContaining(arguments,",;"); stringTrim(string); if(stringLength(string) == 0){ if(stringCharAt(arguments,0) == ',') stringRemoveChar(arguments); Throw(ERR_EMPTY_ARGUMENT); } else if(stringLength(string) == 1){ location = stringCharAt(string,0); if(location == 'F') returnInt = 1; else if(location == 'W') returnInt = 0; else{ returnChar = stringSubstringInChar(string,0,string->length); returnInt = evaluate(returnChar); } } else{ returnChar = stringSubstringInChar(string,0,string->length); returnInt = evaluate(returnChar); } free(string); return returnInt; }//if f, return 1, w is 0
int areStringsEqual(char* x, char* y) { int lengthX = stringLength(x); int lengthY = stringLength(y); if (lengthX != lengthY) { return 0; } int i; for (i = 0; x[i] != '\0' || y[i] != '\0'; i++) { if (x[i] != y[i]) { return 0; } } return 1; }
void insertString (char source[], char insert[], int index) { int stringLength (const char string[]); int i, sourceLen, insertLen; sourceLen = stringLength(source); insertLen = stringLength(insert); for (i = sourceLen; i >= index; --i) source[i + insertLen] = source[i]; for (i = 0; i < insertLen; ++i) source[i + index] = insert[i]; }
OsFile& OsFile::operator <<(float value) { char buf[128]; toCString(value, buf, lengthOf(buf), 7); write(buf, stringLength(buf)); return *this; }
OsFile& OsFile::operator <<(u64 value) { char buf[30]; toCString(value, buf, lengthOf(buf)); write(buf, stringLength(buf)); return *this; }
TestResult* stringLengthTestTemplate(char* x, int expected, char* testName) { int actual = stringLength(x); TestResult* r = malloc(sizeof(TestResult)); r -> testName = "stringLengthTest"; r -> passed = areIntEqual(actual, expected); return r; }
void fillDeviceList(const char* dev, DeviceList& device_list) override { const char* token = nullptr; int device_index = 0; const char* end = dev + stringLength(dev); while (end > dev) { token = reverseFind(dev, token, ':'); char device[32]; if (token) { copyNString(device, (int)sizeof(device), token + 1, int(end - token - 1)); } else { copyNString(device, (int)sizeof(device), dev, int(end - dev)); } end = token; device_list.m_devices[device_index] = getDevice(device); ASSERT(device_list.m_devices[device_index]); ++device_index; } device_list.m_devices[device_index] = nullptr; }
/*Even more stylish animation of provided string*/ void neonAnimation(char* text, int line) { int i = 0, origin = 0, length = 0; length = stringLength(text); origin = 40 - (length/2); /*Print it on the center of chosen line*/ for (i = 0; i <= length; i++) { move(line, origin+i); printw("%c", text[i]); wrefresh(stdscr); Sleep (NORMSPEED); } i = 0; /*De-print it*/ for (i = 0; i <= length; i++) { move(line, origin+i); printw(" "); wrefresh(stdscr); Sleep (NORMSPEED); } }
/*This function additionally moves the cursor just behind the string that has *been just printed*/ void printAndWriteFrom(int row, char* text) { int i = 0, length = 0; length = stringLength(text); /*TODO: Temporary solution for too long strings, need to refine it*/ if (length > 70) { length = 70; } /*Let's first clear what has been written here*/ move(row, 0); for (i = 0; i <= WIDTH-1; i++) { printw("%c", asciiTerminal[i][row-1]); } /*And now write what we wan't to write there*/ move(row, 4); for (i = 0; i <= length; i++) { printw("%c", text[i]); wrefresh(stdscr); Sleep (TSPEED); } /*Storage the cursor's position in order to make printFrom place the cursor in the right place*/ move(row,4 + i-1); getyx(curscr, curY, curX); }
/*Stylish animation of one line of text*/ void invardTextLineSlide(int line, char* whatToPrint) { int j, i, length, begin; length = stringLength(whatToPrint); /*Check parity of length*/ if (length%2 == 1) { j = 40 + ((length+1)/2); } else { j = 40 + (length/2); } i = 40 - (length/2); /*Will print chosen line from 'borders' of the line, inwards*/ for (begin = 0; begin <= length; begin++) { move(line,i); printw("%c",whatToPrint[begin]); move(line,j); printw("%c",whatToPrint[length]); wrefresh(stdscr); Sleep (FASTSPEED); length--; j--; i++; } }
char* SumCharsAndDigits(const char* str) { int total = 0; int i = 0; //if(str != NULL) // on vérifie que la chaine est initialisée //{ int length = stringLength(str); for(i=0; i<length; ++i) { if(isdigit(str[i])) //si le caractere est un chiffre total += str[i] - '0'; else total += letterID(str[i]); } if (total >= 10) { int res = total % 10; // reste int deca = (total - res) / 10; // dizaine total = res + deca; } //} return (char)total + '0'; }
/*if last number is 1, it will appear with animation*/ void printCenter(int line, char* whatToPrint, int wantToAnim) { int i = 0, origin = 0, length = 0; length = stringLength(whatToPrint); origin = 40 - (length/2); /*Print it on the center of chosen line*/ if (wantToAnim == 1) { for (i = 0; i <= length; i++) { move(line, origin+i); printw("%c", whatToPrint[i]); wrefresh(stdscr); Sleep (TSPEED); } } else { for (i = 0; i <= length; i++) { move(line, origin+i); printw("%c", whatToPrint[i]); } wrefresh(stdscr); } }
END_TEST START_TEST(concatString2) { #line 70 char* str1; char* str2; char* str3; char* expected; char* observed; char* test; test = "beginning middle end"; str1 = getSubString(test, 0, 9); str2 = getSubString(test, 10, 15); str3 = getSubString(test, 16, 19); expected = "beginning middle end"; char* half; half = concatString(str1, str2); observed = concatString(half, str3); fail_unless(strcmp(expected,observed) == 0, "not equal strings"); fail_unless(stringLength(test) == 20, "fail"); }
OutputBlob& OutputBlob::operator << (float value) { char tmp[30]; Lumix::toCString(value, tmp, Lumix::lengthOf(tmp), 6); write(tmp, stringLength(tmp)); return *this; }
char* concat(char* string1, char* string2) { int length1 = stringLength(string1); int length2 = stringLength(string2); int length = length1 + length2; char* string = (char*)malloc(length + 1); int i; for (i = 0; i < length1; i++) { string[i] = string1[i]; } int j; for (j = 0; j < length2; j++) { string[length1 + j] = string2[j]; } string[length1 + j] = '\0'; return string; }
void LuaScript::parseProperties() { static const char* PROPERTY_MARK = "-- LUMIX PROPERTY"; const int PROPERTY_MARK_LENGTH = stringLength(PROPERTY_MARK); const char* str = m_source_code.c_str(); const char* prop = findSubstring(str, PROPERTY_MARK); while (prop) { const char* token = prop + PROPERTY_MARK_LENGTH + 1; Property& property = m_properties.pushEmpty(); token = getToken(token, property.name, sizeof(property.name)); char type[50]; token = getToken(token, type, sizeof(type)); if (compareString(type, "entity") == 0) { property.type = Property::ENTITY; } else if (compareString(type, "float") == 0) { property.type = Property::FLOAT; } else { property.type = Property::ANY; } prop = findSubstring(prop + 1, PROPERTY_MARK); } }
void JsonSerializer::serializeArrayItem(float value) { writeBlockComma(); char tmp[20]; toCString(value, tmp, 20, 8); m_file.write(tmp, stringLength(tmp)); m_is_first_in_block = false; }
int main() { printf("Please input your characters, no longer than the string size of 50.\n"); char input[50]; scanf("%s", input); stringLength(input, 50); return 0; }