You are not logged in.

#1 2005-09-01 03:34:45

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

C character string question...

Is there a quick way to compare a character string with a constant such as "hello" in c?

I'd really like to do this without having to write a function ( i know it wouldn't be hard but...)

Offline

#2 2005-09-01 04:15:13

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: C character string question...

searching google turned up alot of hits...
http://www.gnu.org/software/libc/manual … rison.html


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-09-01 15:55:20

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: C character string question...

Euphoric Nightmare wrote:

Is there a quick way to compare a character string with a constant such as "hello" in c?

I'd really like to do this without having to write a function ( i know it wouldn't be hard but...)

strcmp

void foobles(constr char* str)
{
   if(strcmp(str,"hello whirled") == 0)
      puts("strings are the same");
}

Offline

#4 2005-09-03 20:24:52

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: C character string question...

phrakture wrote:
Euphoric Nightmare wrote:

Is there a quick way to compare a character string with a constant such as "hello" in c?

I'd really like to do this without having to write a function ( i know it wouldn't be hard but...)

strcmp

void foobles(constr char* str)
{
   if(strcmp(str,"hello whirled") == 0)
      puts("strings are the same");
}

That is awesome...I didn't know about strcmp

Offline

Board footer

Powered by FluxBB