LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2003, 11:49 AM   #1
wuck
Member
 
Registered: Sep 2003
Location: barneveld.nl
Distribution: Slackware
Posts: 170

Rep: Reputation: 30
[C] three questions:


one

Code:
for ( x = 1 ; x < argc ; x++ )
		{
			printf ("%i %s\n", x, argv[x]);

			if (argv[x] == "joe")
				printf ("You said joe\n");

		}
If I put this in my main() function, compile it, and say:

$ ./compiledbinary joe

It does not print back 'You said joe'. However, it does print

'1 joe'

Which means that printf 'can read' argv[x], but it seems == 'can't' compare argv[x] with a static string. If I make a variable called foo and put "joe" (char *foo = "joe";) in it, it _does_ work.

:confused:

two

Code:
char a;

switch (a)
{
	case 'A':
	case 'B':
		CatBillGatesDevNull ();
		break;
	case 'C':
		Joseph ();
		break;
	default:
		Ko ();
		break;
}
This is perfectly legal, but is it possible to switch strings? I think so, but I wouldn't know how. It'd be odd that just for strings, we'd be stuck with a whole lot of if statements :)

three

I'd like to write KDE apps with Kdevelop in C. What approach is there?

Last edited by wuck; 10-20-2003 at 11:51 AM.
 
Old 10-20-2003, 11:59 AM   #2
patanaheen
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
one:

the string dont get compared the way you are trying to do ... strings are stored in C as arrays of charaters that are terminated by a NULL ('\0') character... therefore to get what you want do this strcmp(argv,"joe") also add string.h in your header files... for the case of char *foo u are actually comparing two characters which in your case are equal... *foo=argv[x] ...

two:

again string comparision are not inbuilt into C therefore u cannot switch on them use strcmp library function and if statement...

three:

just use one of the wizrds and generate a skeleton program then play with it ... u will get the idea ...
 
Old 10-20-2003, 12:02 PM   #3
tcaptain
LQ Addict
 
Registered: Jul 2002
Location: Montreal
Distribution: Gentoo 2004 from stage 1 baby!
Posts: 1,403

Rep: Reputation: 45
for one:

That's because I don't think you can compare strings with '=='
you need to use strcmp (IIRC)
 
Old 10-20-2003, 12:13 PM   #4
wuck
Member
 
Registered: Sep 2003
Location: barneveld.nl
Distribution: Slackware
Posts: 170

Original Poster
Rep: Reputation: 30
Thank you! I was wondering about a strcmp function somewhere ...

/* looks at wrist */ 10 minutes sweet reply time!

Last edited by wuck; 10-20-2003 at 12:14 PM.
 
Old 10-20-2003, 12:24 PM   #5
wuck
Member
 
Registered: Sep 2003
Location: barneveld.nl
Distribution: Slackware
Posts: 170

Original Poster
Rep: Reputation: 30
/* please never mind */
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
Solaris - Questions! Questions! Questions! qs_tahmeed Solaris / OpenSolaris 2 07-16-2005 05:27 AM
window manager questions and/or theme questions t3gah Linux - Software 2 02-27-2005 04:16 PM
Some questions... CryptDragoon Linux From Scratch 2 02-04-2004 08:28 PM
few questions? pudhiyavan Linux - General 2 10-03-2003 07:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration