473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If statement for strings

saza
4 New Member
heyya! i have this problem with my program. i want to make an if argument;

if username is not equal to "admin"
do this
else
do that
......

i already declare the variable username as character: see my code below

......
.......
char username[45];

scanf("%s", username);

if (username != "admin")
{
go to 1
}
else
{
go to 2
}

the input; admin

the output; always be 'go to 1' even when i entered "admin"

can someone help me how can i make the arguments work?

thanks!
Feb 28 '07 #1
3 2771
Ganon11
3,652 Recognized Expert Specialist
You should use strcmp instead of !=. strcmp takes two char* arguments and returns 0 if they are equal, 1 if the first is greater than the second, and -1 if the first is less than the second. So you can use

Expand|Select|Wrap|Line Numbers
  1. strcmp(username, "admin")
to see if they are equal.
Feb 28 '07 #2
saza
4 New Member
that was fast~

it works, thank you so much!!
Feb 28 '07 #3
Ganon11
3,652 Recognized Expert Specialist
Glad to help, and glad you got it working!
Feb 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4857
by: ron | last post by:
Hi, I'm still new at Python and have been away from programming for a number of years in general. I apologized in advance if this has been discussed extensively already. Is the input()...
9
2293
by: François Pinard | last post by:
Hi, people. I hope someone would like to enlighten me. For any application handling Unicode internally, I'm usually careful at properly converting those Unicode strings into 8-bit strings before...
6
8157
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
4
2850
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following...
2
3816
by: Mark Mullins | last post by:
have code below: Function ClassColl(strClass As Variant, strColl As Variant) As String ' Comments : ' Parameters : strClass ' strColl ' Returns : String Description '...
9
2349
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
5
7462
by: Digital Fart | last post by:
I have 3 strings containing "10" , "20", ">=" would it be possible via reflection to generate a dynamic if statement that return true or false and testing it like this if ( 10 >= 20 ) so a...
6
3268
by: chsadaki | last post by:
Hello I have a problem in retrieving a row form a table that I created in mysql db. I insert these values in the table 'Bell',password('123'). But the problem is in my php application I cant...
7
22110
by: priyanka | last post by:
Hi there, I had a question. Is there any way of testing a string value in a switch statement. I have about 50 string values that can be in a string variable. I tried cheking them with the if...
13
1978
by: mcfly1204 | last post by:
I have numerous strings that I would like to run though a switch statement. These strings are terms such as "None" or "Undefined", that I would like to set to Null. My first thought was to create...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.