/****************************************** * TESTSTR - Test Common String Functions * ******************************************/ #include #include #include #include char slen, scmp, spos, stot; const char frst = "string one."; const char scnd = "string two."; char temp[32]; char dest[32]; const char less = "less"; const char more = "more"; const char most = "most"; const char test = "test"; const char pass = "Pass "; const char fail = "Fail "; main: //Test strchr puts("test="); putln(&test); puts("strchr('t', &test): "); spos = strchr('t', &test); if (spos = 0) puts(&pass); else puts(&fail); puts("strchr('s', &test): "); spos = strchr('s', &test); if (spos = 2) puts(&pass); else puts(&fail); puts("strchr('x', &test): "); spos = strchr('x', &test); if (spos = $FF) putln(&pass); else putln(&fail); //Test strrch puts("strrch('t', &test): "); spos = strrch('t', &test); if (spos = 3) puts(&pass); else puts(&fail); puts("strrch('s', &test): "); spos = strrch('s', &test); if (spos = 2) puts(&pass); else puts(&fail); puts("strchr('x', &test): "); spos = strchr('x', &test); if (spos = $FF) putln(&pass); else putln(&fail); //Test strlen puts("strlen(&test): "); slen = strlen(&test); if (slen = 4) putln(&pass); else putln(&fail); newlin(); //Test strcmp puts("less="); puts(&less); puts(" more="); puts(&more); puts(" most="); putln(&most); putln("strdst(&more)"); strdst(&more); puts("strcmp(&most): "); scmp = strcmp(&most); if (scmp :-) puts(&pass); else puts(&fail); puts("strcmp(&more): "); scmp = strcmp(&more); if (!scmp) puts(&pass); else puts(&fail); puts("strcmp(&less): "); scmp = strcmp(&less); if (scmp > 0) putln(&pass); else putln(&fail); newlin(); //Test strcpy, strcat, strstr temp[0] = 0; //Clear temp puts("temp="); puts(&temp); puts(" frst="); puts(&frst); puts(" scnd="); putln(&scnd); putln("strdst(&temp)"); strdst(&temp); puts("strcpy(&frst): "); strcpy(&frst); scmp = strcmp(&frst); if (scmp = 0) puts(&pass); else puts(&fail); puts("strcmp(&frst): "); scmp = strcmp(&frst); if (scmp = 0) puts(&pass); else puts(&fail); puts("strcat(&scnd): "); slen = strlen(&temp); stot = strlen(&scnd) + slen; strcat(&scnd); if (strlen(&temp) == stot) putln(&pass); else putln(&fail); puts("strstr(&frst): "); spos = strstr(&frst); if (spos = 0) puts(&pass); else puts(&fail); puts("strstr(&scnd): "); spos = strstr(&scnd); if (spos = slen) puts(&pass); else puts(&fail); puts("strstr(&test): "); spos = strstr(&test); if (spos = $FF) putln(&pass); else putln(&fail); putln("strdst(&dest);"); strdst(&dest); puts("strcut(slen, &temp): "); stot = strcut(slen, &temp); scmp = strcmp(&scnd); if (scmp = 0) putln(&pass); else putln(&fail); goto exit;