コード例 #1
0
ファイル: Lab6.c プロジェクト: Lagaunne-Timotius/classes
void frequency(int a[],int b[],int c)
{
	int counter;
	for(counter=0;counter<c;counter++)
	{
			b[counter]=count_numbers(a,c,counter);
	}
}
コード例 #2
0
ファイル: StrCalc.c プロジェクト: maicao/TDD-c
/*
 * 	Parse a string of numbers and returns an array with that numbers
 * 	and the lenght of array
 */
int parse_n_str(char s[], int **pn)
{
    int len, ind, count, start, end, n_count=0, num;
    int *n=NULL;
    char buf[10];

    count = count_numbers(s);
    *pn = (int*) malloc(count * sizeof(int));
    if (*pn == NULL) {
        dout("No resources.", NULL);
        return -1;
    }
    n = *pn;

    len = strlen(s);
    dout("There are %d number in %d caracteres.", count, len);

    start = 0;
    for (ind = 0; ind < len; ind++) {
        dout("ind is %d", ind);
        if (strchr(delim, s[ind])) {
            end = ind;
            dout("start: %d, end: %d - %s", start, end, &s[start]);
            memset(buf, 0, sizeof(buf));
            strncpy(buf, &s[start], end - start);
            num = atoi(buf);
            dout("buf is %s num is %d", buf, num);
            n[n_count] = num;
            dout("n[%d] (%p) = %d", n_count, &n[n_count], n[n_count]);
            n_count++;
            start = ind+1;
            /*break;*/
        }
    }

    /* trata strings sem delimitador no final*/
    dout("ind is %d", ind);
    if (!strchr(delim, s[ind-1])) {
        end = ind;
        dout("start: %d, end: %d", start, end);
        memset(buf, 0, sizeof(buf));
        strncpy(buf, &s[start], end - start);
        num = atoi(buf);
        dout("buf is %s num is %d", buf, num);
        n[n_count] = num;
        dout("n[%d] (%p) = %d", n_count, &n[n_count], n[n_count]);
        /**(pn + n_count * sizeof(int)) = num;*/
        n_count++;
    }

    dout("count: %d, n_count: %d", count, n_count);
    return count;
}