Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fucking C

Name: Anonymous 2012-11-03 14:43

Why it doesn't show me strings like "  a"?
Why is the while loop in the trim function bugged (if I input 2 chars the next input length can't be less than 2)?

#include <stdio.h>

#define MAX 1001

int getLine(char s[], int length){ // returns 1 or 0

    int i, qttWord = 0; //qttWord = counter of letters for s[]
    int c; // c = getchar()

    /*Reads the input and puts it into s[], then, verifies if the input is just \n,
    * if so, returns 0(i), if not, puts '\0' at the end of the string.
    */
    for (i = 0; i < length-1 && (c = getchar()) != EOF && c != '\n'; ++i){
            s[i] = c;
            ++qttWord;

    }
    if (i == 0){
        return 0;
    } else if (c == '\n'){
        ++i;
        s[i] = '\0';

    }
    /*Verifies if the string is just ' ' or '\t'
    * if so, returns 0
    */
    char flag = '\0';
    for (i = 0; i < qttWord && flag != '1'; ++i){
        if (s[i] == ' ' || s[i] == '\t'){
            flag = '0';
        } else{
            flag = '1';
        }
    }
    if (flag == '0')
        return 0;

    return qttWord;
}
void trim(char s[], int length){

    char s2[MAX];
    int i, qttWord = 0;

    /*while (s[length] != '\0'){
        ++length;
    }
    printf("length:%d\n", length);*/
    for (i = 0; i < length; ++i){
        if (i < length-1){
            if (s[i] == ' ' && s[i+1] != ' '){
                s2[i] = s[i];
                ++qttWord;
                printf("1:%d\n", s2[i]);// if true prints "1" and the character(' ')
            }
        }
        if (s[i] != ' '){
            s2[i] = s[i];
            ++qttWord;
            printf("0:%d\n", s2[i]);//if true prints "0" and the character
        }
    }
    s[0] = '\0';
    s2[qttWord] = '\0';

    for (i = 0; i < qttWord; ++i){
        s[i] = s2[i];
    }
    s2[0] = '\0';
}

int main(){
    char line[MAX];
    int lgh = 0;

    while ((lgh = getLine(line, MAX)) != 0){
        trim(line, lgh);
        printf("%s\n", line);
        line[0] = '\0';
        lgh = 0;
    }
    return 0;
}

Name: Anonymous 2012-11-05 5:04

>>92

I'll avoid defining collection of objects by redefining set and element of. I'm also throwing out objects.

If X and Y are sets, the proposition X is an element of Y is a statement that is either true or false.

A proposition is a statement that is either true or false. A proposition that is true cannot be false. A proposition that is false cannot be true. A proposition cannot be neither true nor false. A proposition cannot be both true and false.

The set of real numbers can be defined as the set of all equivalence classes of Cauchy sequences of rational numbers.

This is going to take a while.

PART 1:

A relation R on a set X is a relation from the set to itself. That is R is a subset of X*X.

A relation R on a set X is called reflexive if each element of X is related to itself.
\forall x \in X, (x,x) \in R

A relation R on a set X is called symmetric if for each x,y in X, if x is related to y whenever y is related to x.
\forall x,y \in X, (x,y) \in R -> (y,x) \in R

A relation R on a set X is called transitive if for each x,y,z in X, x is related to z whenever x is related to y and y is related to z.
\forall x,y,z \in R, ((x,y) \in R and (y,z) \in R) -> (x,z) \in R

A relation R on a set X is called an equivalence relation if R is transitive, symmetric, and transitive.

If X is a set and Y is the empty set, the proposition X is an element of Y is always false.

If X is a set, Y is a set, W is a set, and Z is the intersection of X and Y, then W is an element of Z only when W is an element of X and W is an element of Y.
(W \in X and W \in Y) <-> W \in Z

If X is a set, Y is a set, W is a set, and Z is the union of X and Y, then W is an element of Z only when W is either an element of X or W is an element of Y.
(W \in X or W \in Y) <-> W \in Z

If X is a set and Y is a set, X is equal to Y if and only if X is a subset of Y and Y is a subset of X.

If X is a set, P is a partition of X if P is a set of subset of X such that the following are satisfied:

If A is a set, B is a set, and A is an element of P and B is an element of P, then the intersection of A and B is equal to the empty set.

The union of all elements of P is equal to X.


If R is an equivalence relation on a set X, a maximal subset of X in which all elements are mutually related to one another is called an equivalence class of X.

Provable result: The set of all equivalence classes of X forms a partition of X.

Zero is the empty set.

If X is a set, then Y is the successor of X if Y is the smallest super set of X such that X is an element of Y.

If Y is a set, then X is the predecessor of Y if Y is the successor of X.

If X is a set, X is called a natural number if it is zero or if it is the successor of a natural number.

If X, Y, Z are natural numbers, Z is the sum of X and Y if any of the following are satisfied:

Z is equal to X and Y is equal to zero.
Z is equal to Y and X is equal to zero.
Z is the sum of the successor of X and the predecessor of Y.

If X, Y, Z are natural numbers, Z is the subtraction of X and Y if any of the following are satisfied:

Z is equal to X and Y is equal to zero.
Z is the subtraction of the predecessor of X and the predecessor of Y.

one is the successor of zero.

If X, Y, Z are natural numbers, Z is the multiplication of X and Y if any of the following are satisfied:

Z is equal to zero and X is equal to zero
Z is equal to zero and Y is equal to zero
Z is equal to X and Y is equal to the one.
Z is equal to Y and X is equal to the one.
Z is the sum of X and the multiplication of the X and the predecessor of Y.


If X, Y, Z are natural numbers, Z is the division of X and Y if X is the multiplication of Z and Y.

If X, Y are natural numbers, X is greater than or equal to Y if there is a natural number Z such that X is the sum of Y and Z.

If X, Y are natural numbers, X is called a divisor of Y is there exists a natural number Z such that Z is the division of Y and X.

If X, Y, Z are natural numbers, Z is called the greatest common divisor of X and Y if Z is a divisor of X, Z is a divisor of Y, and if W is a natural number such that W is a divisor of X and W is a divisor of Y, then Z must be greater than or equal to W.

A rational number is a pair of natural numbers whose greatest common divisor is one.

to be continued...

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List