C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2009, 03:21 PM   #1
Registered User
 
Join Date: Nov 2009
Posts: 3
Strings and if

Instead of trying to explain what I am attempting to do I'll just post the code:
Code:
int main() {
	char answer [50];
	char ans1;

	
	printf("Work out?\n");
	scanf("%s", answer);
	
	if (answer=='Pressure') {
		printf("worked");
	}
	else {
		printf("nope");
	}
As you would know that is a big bowl of fail :P been trolling around the internet trying to find out how to go about if statements and strings and cant find anything (apart from with c++ and that just confuses me even more).

Would be grateful if anyone could spare some in-sight
Xandan is offline   Reply With Quote
Old 11-26-2009, 03:22 PM   #2
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,461
Use strcmp and compare to 0.
Also, single quotes means one character, and double quotes means a string.
So, 'a' = a char, "a" = a string (char*).

Also, read up on Scanf woes.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 11:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22