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-24 9:15

multiple threads XD

Name: Anonymous 2009-05-24 9:21


int i;

if(sscanf(s, "%*[a-z0-9]%n", &i) > 0 && s[i] == 0)

Name: Anonymous 2009-05-24 9:26

>>3
Thanks i'll try that.

Name: Anonymous 2009-05-24 9:29

>>3
[b][u]DONT HELP HIM[/i][/b]

Name: Anonymous 2009-05-24 9:59

Use Regular Expressions.

Name: Anonymous 2009-05-24 10:24

>>6
[b][u]YOU JUST ANGRED AN FUQEN REGUlAR EXPRESSION PROGRAMMER[/][/b]

Name: Anonymous 2009-05-24 10:43

>>7
Is that covered in Computer Science III?

Name: Anonymous 2009-05-24 10:57

>>8
Return to Encyclopedia Dramatica, please.

Name: Anonymous 2009-05-24 11:29

>>9
Fuck you, I was there when it happened.

Name: Anonymous 2009-05-24 11:34

>>5
>>7
Are you even trying?

Name: Anonymous 2009-05-24 11:43

>>10
Return to /b/, please.

Name: Anonymous 2009-05-24 11:47

Double, double, toil and trouble
Fire burn and hax my anus bubble.

Name: Anonymous 2009-05-24 12:01

>>3,1
if (!s1[strspn(s1, "abcdefghijklmnopqrstuvwxyz0123456789")])

Name: Anonymous 2009-05-24 12:14

use sed

Name: Anonymous 2009-05-24 13:17

>>14
Seems even faster.

Name: Anonymous 2009-05-24 13:19

>>14 strspn
EXPERT C standard library user.

Name: Anonymous 2009-05-24 13:49

Embed lua.

Name: Anonymous 2009-05-24 13:53

>>14
This approach stinks, faggot. You are allocating 36 bytes in your .rodata section. What a poor way of programming!

Name: >>14 2009-05-24 16:27

>>19
I think you mean 37.

Name: Anonymous 2009-05-24 18:01

for(int i=0; i<str_length; i++){
   switch(str[i]){
      case 'a':
          //do something
          break;
      case 'A':
          //do something
          break;
      case 'b':
          //do something
          break;
      case 'B':
          //do something
          break;
      case 'c':
          //do something
          break;
      case 'C':
          //do something
          break;
      case 'd':
          //do something
          break;
      case 'D':
          //do something
          break;
      case 'e':
          //do something
          break;
      case 'E':
          //do something
          break;
      case 'f':
          //do something
          break;
      case 'F':
          //do something
          break;
      case 'g':
          //do something
          break;
      case 'G':
          //do something
          break;
      case 'h':
          //do something
          break;
      case 'H':
          //do something
          break;
      case 'i':
          //do something
          break;
      case 'I':
          //do something
          break;
      case 'j':
          //do something
          break;
      case 'J':
          //do something
          break;
      case 'k':
          //do something
          break;
      case 'K':
          //do something
          break;
      case 'l':
          //do something
          break;
      case 'L':
          //do something
          break;
      case 'm':
          //do something
          break;
      case 'M':
          //do something
          break;
      case 'n':
          //do something
          break;
      case 'N':
          //do something
          break;
      case 'o':
          //do something
          break;
      case 'O':
          //do something
          break;
      case 'p':
          //do something
          break;
      case 'P':
          //do something
          break;
      case 'q':
          //do something
          break;
      case 'Q':
          //do something
          break;
      case 'r':
          //do something
          break;
      case 'R':
          //do something
          break;
      case 's':
          //do something
          break;
      case 'S':
          //do something
          break;
      case 't':
          //do something
          break;
      case 'T':
      .........
   }
}

Name: Anonymous 2009-05-24 18:09

>>19
oh noes 36 bytes, whatever will we do says the person who spent a week shrinking his Uni project to a quarter it's original size

Name: Anonymous 2009-05-24 19:49

>>22
This one time I developed a game in Sepples for a Uni project. I ended up running out of time so I tried to focus on finishing the actual game. Even though I did complete it, I ended up turning it in with 29 memory leaks still there and I feel kind of bad about it :(

Name: Anonymous 2009-05-24 19:50

i implemented mozart's rondo alla turca in lisp

Name: Anonymous 2009-05-24 22:05

>>23
What grade did you end up with?

Name: Anonymous 2009-05-24 22:10

>>25
A lowly B+

Name: Anonymous 2009-05-24 22:17

C's string handling sucks. Length-prefix is obviously superior.

Trying to handle strings fast and efficiently in C is like trying to build web servers in lisp.

Name: Anonymous 2009-05-24 22:21

>>27
Length-prefix is obviously superior.
Ironic, thats exactly how C string handling works in my string struct. I think it's you who doesn't understand the basic idea of C in that there is nothing you can't do yourself.

Name: Anonymous 2009-05-25 1:15

>>28
So what you're saying is that it has nearly zero value to the modern programmer. If it didn't allow such tight control over memory, it would definitely be worthless for any practical purposes.

Name: Anonymous 2009-05-25 4:15

>>27
What's wrong with building web servers in Lisp? Edi's even done all the work for you.

Name: Anonymous 2009-05-25 5:11

Google is written in LISP

Name: Anonymous 2009-05-25 8:33

Bump for all to have a laugh at >>27 who doesn't understand C's strings are primitive and this "length prefix" is a feature on top of them.

Name: Anonymous 2009-05-25 8:45

>>32
Play nice, it's not his fault he's retarded

Name: Anonymous 2009-05-25 10:46

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

Name: Anonymous 2009-05-25 11:06

>>34
Superior iterative version.

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 12:01

>>35
How is it superior if it uses fucking failure(TM) indentation style?

Name: Anonymous 2009-05-25 12:31

>>36
This is C, not Haskell. We don't support purely fictional indentation styles here.

Name: Anonymous 2009-05-25 12:33

>>36
fucking failure? You don't know what you're talking about. Indentation in >>34 is PIG DISGUSTING!!

Name: Anonymous 2009-05-25 12:33

>>36
Faggot. I bet you enjoy single closing braces with no sign of its opening brother in the vertical line, faggot.

Name: Anonymous 2009-05-25 12:35

>>35-39
Idiots, GNU-style indentation is superior

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