I know Perl, and I'm so used to the operators for it.
For example, in perl..
What is the C equivalent?Code:if($input =~ /help (.*)/) { $command = $1; if($command eq "echo") { #Example } else { print "Command not found.\n"; } }
Thanks,
Austin B.
This is a discussion on String comparing in C within the C Programming forums, part of the General Programming Boards category; I know Perl, and I'm so used to the operators for it. For example, in perl.. Code: if($input =~ /help ...
I know Perl, and I'm so used to the operators for it.
For example, in perl..
What is the C equivalent?Code:if($input =~ /help (.*)/) { $command = $1; if($command eq "echo") { #Example } else { print "Command not found.\n"; } }
Thanks,
Austin B.
Well if you want the first line with any degree of utility, you'll need this
http://www.pcre.org/
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
"strcmp" compares two different strings
Eg: strcmp(a,b); compares a and b, if they are equal returns a zero value, if less a value less than zero and if greater oh well u know![]()
I know about strcmp, I just want something that will allow you to do something like this.
Like an IRC bot:
Person: !add Person
Bot: Person is added to the Messaging List.
Person2: !add Person2
Bot: Person2 is added to the Messaging List.
Make sense?
Well, but what does that have to do with string comparing? Do you mean "how do I read in a string"? What?
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
Code:if(strstr(buffer, "!add") == buffer) /* do stuff */
Finally, sounded like I was talking to a wall.
Thank you, Master5001.
Oh, are you in for some fun. I think the nature of string ops in C were the motive for creating perl, but you'll have to check w/ Mr. Wall.
Master5001 is being tricky here. You should look up strcmp as well.
Code:if (strcmp(command, "echo")==0) dostuff(); else whatever...
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge