コード例 #1
0
/* Soru 1 */
int r_strchr(char *string, char c) {
    /* TODO */
    
    if(string[0]=='\0')
    return 0;
    if(c==string[0])
    return 1;
    else
    return r_strchr(++string, c);
}
コード例 #2
0
int main(int argc, char *argv[]) {
    /* NOTE: Test kodu, buraya dokunmayin! */

    assert(r_strchr("ahmet mehmet\n\n\t", 'h') == 1);
    assert(r_strchr("ahmet", 'x') == 0);
    assert(r_strchr("ahmet", 'a') == 1);
    assert(r_strchr("hhhhhhha", 'x') == 0);
    printf("All tests passed for r_strchr()!\n");

    assert(r_strlen("ahmet mehmet kokokoko\t\t") == 23);
    assert(r_strlen("ahmet") == 5);
    assert(r_strlen("a") == 1);
    assert(r_strlen("") == 0);
    printf("All tests passed for r_strlen()!\n");

    assert(r_strcount("ahmet", 'a') == 1);
    assert(r_strcount("ahmeta", 'a') == 2);
    assert(r_strcount("ahmeta", 'x') == 0);
    assert(r_strcount("", 'x') == 0);
    assert(r_strcount("ahmet mehmet\n\n\t", 't') == 2);
    printf("All tests passed for r_strcount()!\n");

    assert(roman_number_to_int("IIII") == 4);
    assert(roman_number_to_int("IV") == 4);
    assert(roman_number_to_int("VIIII") == 9);
    assert(roman_number_to_int("IX") == 9);
    assert(roman_number_to_int("MIM") == 1999);
    assert(roman_number_to_int("MCMXCIX") == 1999);
    assert(roman_number_to_int("D") == 500);
    printf("All tests passed for roman_number_to_int()!\n");
    
    assert(r_sum_digits(0) == 0);
    assert(r_sum_digits(9) == 9);
    assert(r_sum_digits(10) == 1);
    assert(r_sum_digits(100) == 1);
    assert(r_sum_digits(1009) == 10);
    assert(r_sum_digits(152101) == 10);
    assert(r_sum_digits(999999) == 54);
    printf("All tests passed for r_sum_digits()!\n");

    return 0;
}
コード例 #3
0
int r_strchr(char *string,char c){
	if(string!=NULL || *string!='c'){
		return r_strchr(string+1,c);
	}
	else if(*string=='c'){
		return 1;
	}
	else{
		return 0;
	}
}
コード例 #4
0
ファイル: umut.c プロジェクト: galatasarayuniversity/INF203
/* Soru 1 */
int r_strchr(char *string, char c) {
    /* TODO */
    int i;
    for (i=0; i<string; i++) {
        if (r_strchr(string,c)!=0) {
            return 0;}
        else{
            return 1;
        }
        
        }
    }
コード例 #5
0
ファイル: rexcompiler.c プロジェクト: MasterQ32/rpatk
static int rex_compiler_isblank(rexcompiler_t *co, int c)
{
	return r_strchr(co->blankchars, c) ? 1 : 0;
}
コード例 #6
0
ファイル: rexdfa.c プロジェクト: MasterQ32/rpatk
void rex_dfa_dumpstate(rexdfa_t *dfa, rexuint_t nstate)
{
	long index;
	char buf[240];
	int bufsize = sizeof(buf) - 1;
	int n = 0;
	rexdfs_t *s = rex_dfa_state(dfa, nstate);
	rexdfss_t *ss = NULL;
	rexdft_t *t = NULL;

	if (!s)
		return;
	fprintf(stdout, "State %ld", (unsigned long)nstate);
	fprintf(stdout, " (");
	for (index = 0; index < s->nsubstates; index++) {
		ss = REX_DFA_SUBSTATE(dfa, nstate, index);
		if (ss) {
			fprintf(stdout, "%ld", (unsigned long)ss->uid);
			if (ss->type == REX_STATETYPE_ACCEPT)
				fprintf(stdout, "*");
			if (index + 1 < s->nsubstates)
				fprintf(stdout, ",");
		}
	}
	fprintf(stdout, ")");


	fprintf(stdout, ": ");
	if (s->type == REX_STATETYPE_ACCEPT) {
		fprintf(stdout, " REX_STATETYPE_ACCEPT ");
		fprintf(stdout, " (");
		for (index = 0; index < s->naccsubstates; index++) {
			ss = REX_DFA_ACCSUBSTATE(dfa, nstate, index);
			if (ss) {
				fprintf(stdout, "%ld*", (unsigned long)ss->uid);
				if (index + 1 < s->naccsubstates)
					fprintf(stdout, ",");
			}
		}
		fprintf(stdout, ")");
	} else if (s->type == REX_STATETYPE_DEAD) {
		fprintf(stdout, " REX_STATETYPE_DEAD ");
	} else if (s->type == REX_STATETYPE_START) {
		fprintf(stdout, " REX_STATETYPE_START ");
	}
	fprintf(stdout, "\n");
	for (index = 0; index < s->ntrans; index++) {
		t = &dfa->trans[s->trans + index];
		n = 0;
		if (t->lowin != t->highin) {
			if (isprint(t->lowin) && !isspace(t->lowin) && isprint(t->highin) && !isspace(t->highin) && !r_strchr("[]-^", t->lowin) && !r_strchr("[]-^", t->highin))
				n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "    [%c - %c] ", t->lowin, t->highin);
			else
				n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "    [0x%X - 0x%X] ", t->lowin, t->highin);
		} else {
			if (isprint(t->lowin) && !isspace(t->lowin))
				n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "    '%c' ", t->lowin);
			else
				n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "    0x%X ", t->lowin);
		}
		r_memset(buf + n, ' ', bufsize - n);
		n = 40;
		n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "-> %ld", t->state);
		fprintf(stdout, "%s\n", buf);
	}
	if (!s->ntrans)
		fprintf(stdout, "        (none)\n");
	fprintf(stdout, "\n");
}