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-03 22:43

>>38
A char is a 1-byte variable. As long as it's 1 byte wide, you can put anything on it.

This includes 'a' (01100001 in ASCII), 1 (00000001), '1' (00110001) or 255 (11111111).

Name: Anonymous 2012-11-03 22:46

>>41
In C you only have 7 guaranteed bits in a char, you must use signed or unsigned to get the full 8 bits, char is the only integer type that behaves like this.

Name: Anonymous 2012-11-03 22:48

>>38

It's an integer type just like short, long, int and whatnot.  It is ``meant for'' holding characters, but it can hold any integer value within its range.

char is not necessarily 8 bits.
int is not necessarily larger than char.
sizeof(char) is guaranteed to be 1, however, meaning the sizes of all other types must be multiples of the size of char.

Name: Anonymous 2012-11-03 22:49

>>42
Oops, you're right, sorry about that.

Name: Anonymous 2012-11-03 22:54

>>43
char is not necessarily 8 bits.
whatafuck man

No, seriously, if sizeof(char) is guaranteed to be 1, why wouldn't char be 8 bits?

Name: Anonymous 2012-11-03 23:02

On some machines the ``byte'', or smallest easily-addressable unit of memory, is not 8 bits or even a power of two.  I believe the PDP-11 had 9-bit bytes, and the C compiler for some old Cray used 32- or even 64-bit chars because anything smaller would have required a whole bunch of mask and shift operations for each char access, making it unbelievably slow.

Old IBM machines had 6-bit bytes and 36-bit words, but I'm not sure if C guarantees a minimum width of char that would require it to use two bits on those machines.

Name: 46 2012-11-03 23:02

That was directed at >>45 .

Name: Anonymous 2012-11-03 23:08

>>45
CHAR_BIT

Name: Anonymous 2012-11-03 23:08

>>45
sizeof(char)*CHAR_BITS is the only reliable way of knowing

Name: Anonymous 2012-11-03 23:13

Ok, found the solution.
Although, I don't think what I did with thes2 string is very virtuous...

#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
        s[i] = '\0';
       
    /*Verifies if the string is just ' ' or '\t'
    * if so, returns 0
    */
    for (i = 0; i < qttWord; ++i){
        if (s[i] != ' ' || s[i] != '\t')
            return 1;
    }
    return 0;

}
void trim(char s[]){

    int i, qttWord = 0, length = 0;

    while (s[length] != '\0'){
        ++length;
    }

    char s2[length];
    for (i = 0; i < length; ++i)
        s2[i] = -1;

    for (i = 0; i < length; ++i){
        if (i < length-1){
            if (s[i] == ' ' && s[i+1] != ' '){
                int ii;
                for (ii = 0; ii < length; ++ii){
                    if (s2[ii] == -1){
                        s2[ii] = s[i];       
                        ++qttWord;
                        printf("1:%c\n", s2[ii]);
                        break;
                    }
                }
            }
        }
        if (s[i] != ' '){
           
            int ii;
            for (ii = 0; ii < length; ++ii){
                if (s2[ii] == -1){
                    s2[ii] = s[i];       
                    ++qttWord;
                    printf("0:%c\n", s2[ii]);
                    break;
                }
            }
        }
    }
    s[0] = '\0';
    s2[qttWord] = '\0';
    printf("string2:%s\n", s2);
   
    for (i = 0; i < qttWord; ++i){
        s[i] = s2[i];
        printf("s:%c\n", s[i]);
    }
    s[qttWord] = '\0';
    printf("string:%s\n", s);
    s2[0] = '\0';
}

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

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

Name: Anonymous 2012-11-03 23:22

>>50

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

This is backwards -- it returns 1 for the string "  a".

in trim
    for (i = 0; i < length; ++i){
        if (i < length-1){

This is redundant.

Name: Anonymous 2012-11-03 23:39

>>51
it returns 1 for the string "  a".
It should.
in trim

    for (i = 0; i < length; ++i){
        if (i < length-1){
This is redundant.
Nope.

Name: Anonymous 2012-11-04 0:02

>>43
It's an integer type just like short, long, int and whatnot.  It is ``meant for'' holding characters, but it can hold any integer value within its range.
I never said it wasn't an integer type, however it's not a "signed integer type" which the other types you listed are, signed char is a signed integer type.

If you write short int, int or long int you know that they are signed, you don't know that about char, whether char is signed or unsigned is up to the implementation so if you want to be portable you can only work with the 0-127 range i.e. 7 bits unless you specify with either the signed or unsigned type specifiers.

char is not necessarily 8 bits.
Right, it has to be able to hold at least 8 bits.

int is not necessarily larger than char.
Right, but why are you telling me this?

sizeof(char) is guaranteed to be 1, however, meaning the sizes of all other types must be multiples of the size of char.
Right, but why are you telling me this?

>>45
No, seriously, if sizeof(char) is guaranteed to be 1, why wouldn't char be 8 bits?
It's at least 8 bits, of which you can only 7 bits if you want to be portable when you're using the unspecified char type.

On systems that support the optional types in stdint.h like int8_t and uint8_t CHAR_BIT is exactly 8.

Name: Anonymous 2012-11-04 0:13

>>53
Right, it has to be able to hold at least 8 bits.
Nitpick, but only since C99. Earlier standards just require that it can hold at least 95 values, because it has to be able to hold the basic execution character set. In principle, 7-bit (or 5-trit) chars are possible.

Name: Anonymous 2012-11-04 0:42

>>54
In my version of the ANSI C standard CHAR_BIT is guaranteed to be at least 8.

Name: Anonymous 2012-11-04 0:49

>>55
Chapter and verse, please.

Name: Anonymous 2012-11-04 1:06

>>56
2.2.4.2 Numerical limits

Name: Anonymous 2012-11-04 1:25

>>39
GUIDO quality!

Name: Anonymous 2012-11-04 5:50

for (i = 0; i < length-1 && (c = getchar()) != EOF && c != '\n'; ++i){
   s[i] = c;
   ++qttWord;

}

The above is bullshit, code like a !nigger

for (i = 0; i < length-1;)
{
   c = getchar())
   if(c == EOF || c == '\n')
      break;

   s[i++] = c;
   s[i] = '\0';
}

Name: Anonymous 2012-11-04 6:08

Symta:

yoba M = O:<F [V X@T]={F V X=[V@(r F [X@T])];[V]};F X=X>
       = hyp 0 0 M,0,len M,len
       | m:[X Y] (drop Y M |m (drop X ? | O `≤≤`) | O <A B = B-A | all ?≥≥0>)
       | sort by:?,len*?,0,len | rhd



C/C++:

#include <stdio.h>
 
typedef int bool;
#define true 1
#define false 0
 
struct solution {
  int top_left_x;
  int top_left_y;
  int width;
  int height;
};
 
int main(int argc,char** argv)
{
  const int x_size = 4;
  const int y_size = 4;
  int data[4][4] = {{9,4,5,5},{5,1,3,3},{8,1,4,5},{8,0,5,2}};
 
  int top_left_x;
  int top_left_y;
  int width;
  int height;
 
  struct solution sol;
  sol.top_left_x = -1;
  sol.width = 0;
  sol.height = 0;
 
  // width and height also zero based, so 1 means 2
 
  for (width=1;width<x_size;width++)
  {
    for (height=1;height<y_size;height++)
    {
      for (top_left_x=0;top_left_x<x_size-width;top_left_x++)
      {
        for (top_left_y=0;top_left_y<y_size-height;top_left_y++)
        {
          bool passed = true;
          int i,j;
          //x check
          for (i=0;(i<width) && passed;i++)
          {
            for (j=0;(j<height+1) && passed;j++)
            {
              int k = i + top_left_x;
              int l = j + top_left_y;
              int current = data[l][k];
              int next = data[l][k+1];
              if (current>next)
                passed = false;
            }
          }
 
          //y check
          for (i=0;(i<width+1) && passed;i++)
          {
            for (j=0;(j<height) && passed;j++)
            {
              int k = i + top_left_x;
              int l = j + top_left_y;
              int current = data[l][k];
              int next = data[l+1][k];
              if (current>next)
                passed = false;
            }
          }
 
          if (passed && ((width+1)*(height+1) >= (sol.width+1)*(sol.height+1)))
          {
            sol.top_left_x = top_left_x;
            sol.top_left_y = top_left_y;
            sol.width = width;
            sol.height = height;
          }
        }
      }
    }
  }
 
  int i,j;
  if (sol.top_left_x>-1)
  {
    for (j=0;j<sol.height+1;j++)
    {
      for (i=0;i<sol.width+1;i++)
      {
        printf("%d ",data[j+sol.top_left_y][i+sol.top_left_x]);
      }
      printf("\n");
    }
  }
 
 
  return 0;
}

Name: Anonymous 2012-11-04 6:51

>>60
You don't fuck with my rights to privacy, cretin.

Name: Anonymous 2012-11-04 8:30

>>61
When antisemitism becomes global, crowds will be lynching, you, Jews all around the globe right inside your rich Jewish houses. Anyway, having a private house is immodest and wasteful. Everyone should live in commies blocks.

Name: Anonymous 2012-11-04 8:33

>>62
This is how honest Chinese workers live:
http://www.skyscrapercity.com/showthread.php?t=1516684

American Jews are spoiled and deserve only death.

Name: Anonymous 2012-11-04 11:37

>>60
What does the hyp function do? Or rhd?

I don't know what point you're making here. The second code snippet is readable, the first one isn't. The programs also aren't equivalent. Symta looks... interesting, though.

Name: Anonymous 2012-11-04 12:03

>>64
hyp 3 4 5 6 -> ((1 2) (2 2) (3 2) (1 3) (2 3) (3 3) (1 4) (2 4) (3 4) (1 5) (2 5) (3 5))

Name: Anonymous 2012-11-04 12:04

>>65
hyp 1 2 3 4 -> ((1 2) (2 2) (3 2) (1 3) (2 3) (3 3) (1 4) (2 4) (3 4) (1 5) (2 5) (3 5))


self fix

Name: Anonymous 2012-11-04 12:08

>>60
I hope you die a painful death Shitta fagstorm

Name: Anonymous 2012-11-04 12:09

>>67
Shalom, Chaim!

Name: Anonymous 2012-11-04 12:45

>>58-66
where is sumtra documentad

Name: Anonymous 2012-11-04 12:52

>>68
But Shitta is kike shit

Name: Anonymous 2012-11-04 13:45

>>70
your mom is a kike, shit.

>>69
I gave it to Sussman for review, but he burned the papers, because he hates goyim students.

Name: Anonymous 2012-11-04 13:57

>>59
K&R code is nigger like

Name: Anonymous 2012-11-04 14:04

>>71
Why don't you make a nice websight for Symta and submit it to Hacker News?
[Show HN] Symta, the first kike-free programming language

Name: Anonymous 2012-11-04 14:07

Is floating point arithmetic kike shit?

Name: Anonymous 2012-11-04 14:28

>>73
Why don't you make a nice websight
websites cost money, requiring crap like credit card and passport.

first kike-free
would be closed for anti-semitism.

Name: Anonymous 2012-11-04 14:28

>>74
no. floating point are just rational numbers.

Name: Anonymous 2012-11-04 14:35

>>76
rational numbers can be infinite series

Name: Anonymous 2012-11-04 14:47

>>76
floating point is approximate, you FUCKING RETARDED STUPID SHIT GUY FUCKER ANUS

Name: Anonymous 2012-11-04 15:53

real numbers are limits of series of rationals, eat shit jew spammer

Name: Anonymous 2012-11-04 16:00

>>79
U MENA sequences

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