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

check string in c

Name: Anonymous 2009-05-24 9:14

what the fast way to check that string contain only characters within some set like "a-z0-9"?

Name: Anonymous 2009-05-25 13:20

>>40
Excuse me, could you repeat that? It was kind of hard to make out with all that cocks stuffed in your mouth.

Name: Anonymous 2009-05-25 13:26

"All that cocks stuffed"

English major.

Name: Anonymous 2009-05-25 13:26

"It was kind of hard"
-- >>41

Name: Anonymous 2009-05-25 13:29

Whenever I write in C, I use the >>35 style of indentation.

Name: Anonymous 2009-05-25 13:30

Anyone who doesn't use allman-based style is a flaming cretin. But I guess some people prefer to line up their closing braces not to their respective opening braces, but to something like the fuqin int fun.

Name: Anonymous 2009-05-25 13:35

>>44
Aww, I already had a post that involved a chest of cocks and a dicksage, but then I clicked the link and realised that you use the correct indention. :(

Name: Anonymous 2009-05-25 13:41

int
is_inset(s)
const char *s;
  {
    while (*s)
      {
        if (!(*s>='a' && *s<='z' || *s>='0' && *s<='9'))
          {
            return 0;
          }
        ++s;
      }
    return 1;
}


Fixed you're code.

Name: Anonymous 2009-05-25 13:43

>>35 is the indentation style that my highschool C teacher taught to the class, and they always asked me help fix their code whenever the screwed it up. Because of that I have always and will forever associate that style with complete idiots.

Name: Anonymous 2009-05-25 13:48

>>47
WHAT
THE
FUCK
 BRO

Code is supposed to look tidy.

Name: Anonymous 2009-05-25 13:56

>>49
I messed up that last brace, but with that fixed it would look beautiful.

Name: Anonymous 2009-05-25 13:58

>>48
The braces on their own lines make simple functions too long but every other style looks weird to me. I'd rather FOIC than C, but sometimes C is best.

Name: Anonymous 2009-05-25 14:12

>>51
For very short functions (like inline ones) I use
int max(int a, int b) {
    return (a > b ? a : b); }

Nearly like FIOC.

Name: Anonymous 2009-05-25 14:17

int
main
                      (
 int argc, char **argv
)
          {
 return 0;
}

Name: Anonymous 2009-05-25 14:25

>>53
This is now the official indentation style of /prog/

Name: Anonymous 2009-05-25 14:31

>>54
I should'f patented it.

Name: Anonymous 2009-05-25 14:35

>>53-55
Clarification required: is the opening brace placed after the end of the line following it, or after the longest line in the block following it?

Name: Anonymous 2009-05-25 14:40

>>52
You know you can skip the braces if you only have one line, right?

Name: Anonymous 2009-05-25 14:43

>>57
I know you can do that when you have if statements etc., but is it possible with functions?

Name: Anonymous 2009-05-25 14:44

>>56
The latter.
int
main
              (
 int     argc,
 char  **argv
)
          {
 return 0;
}

Name: Anonymous 2009-05-25 14:46

>>59
Though that example doesn't really show it.
int
main
              (
 int     argc,
 char  **argv
)
                    {
 const char *s;
 s = "Hello world!";
 printf("%s", s);
 return 0;
}

Name: Anonymous 2009-05-25 15:13

int is_inset(const char*s){while(*s){if (!((*s>='a'&&*s<='z')||(*s>='0'&&*s<='9')))return 0;++s;}return 1;}
BEST STYLE

Name: Anonymous 2009-05-25 15:21

>>60
Excellent. I shall adopt this style.

Name: Anonymous 2009-05-25 15:22

>>61
Amateur optimizer. You forgot one space after if.

Name: Anonymous 2009-05-25 15:24

>>62
Me to.

We could use it as a Shibboleth.

Name: Anonymous 2009-05-25 15:32

>>60
Nested blocks:

int main
                      (
 int argc, char **argv
)
                         {
 int i = 1;
 while
          (
  i < argv
 )
                        {
  printf("%s", argc[i]);
  ++i;
 }
 return 0;
}


I wish to hear your suggestions!!

Name: Anonymous 2009-05-25 15:42

>>65
int main
                      (
 int argc, char **argv
)
                            {
 int a, b, c, d, e, f;
 if (b)
            {
  a++++++--;
 }
 return (d+e+f > a)?'y':'n';
}


Works for me.

Name: Anonymous 2009-05-25 15:42

>>65
line breaks in the for loops.

Name: Anonymous 2009-05-25 15:43

>>63
Oh snap!
Allow me to re-optimize:
int is_inset(const char*s){while(*s){if(!((*s>='a'&&*s<='z')||(*s>='0'&&*s<='9')))return 0;++s;}return 1;}

Name: Anonymous 2009-05-25 15:45

>>67
As in
for
           (
 int i = 0;
 i < argc;
 ++i
)
               {
 //do something
}

?

Name: Anonymous 2009-05-25 15:49

>>68
int is_inset
                   (
const char*s
)
                   {
while
                   (
*s
)
                   {
if
                   (
!
                   (
                   (
*s>='a'
&&
*s<='z'
)
||
                   (
*s>='0'
&&
*s<='9'
)
)
)
return 0;
++s;
}
return 1;
}

Name: Anonymous 2009-05-25 15:55

>>68
is_inset(char*s){while(*s){if(!(*s>'`'&&*s<'{'||*s>'/'&&*s<':'))return 0;++s;}return 1;}

Name: Anonymous 2009-05-25 15:57

>>68,70

int
              is_inset
                 (
    const             char
  *           s              )
       {                while
(   *s    
                   )  {
 if       (    !(               ( *s
    >=        'a'   
                      &&
                           *s
    <=           'z'               )
 ||          (          *s
        >=
               '0'
                       &&
  *s                           <=
          '9'       )))
      return
                        0     ;
    ++s          ;         }
           return        1
                   ;
}

Name: Anonymous 2009-05-25 16:01

>>71
A little faster using Fast Logic operators.
is_inset(char*s){while(*s){if((*s<'0'|*s>'9')&(*s<'a'|*s<'z'))return 0;++s;}return 1;}

Name: Anonymous 2009-05-25 16:02

>>73
(*s<'a'|*s<'z')
I think you missed something.

Name: Anonymous 2009-05-25 16:02

>>72
This is the most amazing indentation I've seen in my life. Please take me as your student, master.

I think I can see a face in there

Name: Anonymous 2009-05-25 16:05

>>74
Thanks Anonymous.

Here's the next iteration. I'm not sure about the return value though, it might need one more !.

is_inset(char*s){while(*s&(*s<'0'|*s>'9')&(*s<'a'|*s>'z'));return!*s;}

Next up is removing the extra set of parentheses.

Name: Anonymous 2009-05-25 16:07

>>76
There, much better.

is_inset(char*s){while(*s&&*s<'0'|*s>'9'&&*s<'a'|*s<'z');return!*s;}

Name: Anonymous 2009-05-25 16:08

>>77
Forgot to change the < to a > here.

is_inset(char*s){while(*s&&*s<'0'|*s>'9'&&*s<'a'|*s>'z');return!*s;}

Name: Anonymous 2009-05-25 16:10

>>75
Can you answer this question: TARO or Xarn?

Name: Anonymous 2009-05-25 16:11

>>78
Argh, forgot && only evaluates as much as is needed. Also needs an increment of s.

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