LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-10-2003, 06:57 PM   #16
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374

Essentially, yes. I handle strings a little differently than the way you have. Just how I learned them is all...
Code:
#include <stdio.h>
#include <string.h>

#define STRING_LENGTH 17  // max # of characters + 1
                          //   completely arbitrary
int main(void)
{
  int x;
  char s1[STRING_LENGTH]; // how I'm used to seeing it
  char s2[STRING_LENGTH]; // .. ditto ..

  strcpy ("password", s1);  // Copy the string into s1

  printf(" Enter a password:\n");
  scanf("%s", s2);

  x = strcmp(s1,s2);
  if (x == 0)
    printf("password accepted");
  else
    printf("access denied");
              
  return(0);
}

Last edited by Dark_Helmet; 03-10-2003 at 09:58 PM.
 
Old 03-10-2003, 07:00 PM   #17
Randall
Member
 
Registered: Oct 2001
Location: Ontario, Canada (for now, i'm from NJ )
Distribution: Redhat 7.2
Posts: 106

Original Poster
Rep: Reputation: 15
that seems to work so far, i'll continue writing the program and i'll see what other bumps come up!


thanks for your help! i REALLY REALLY appreciate it
 
Old 03-10-2003, 09:23 PM   #18
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
in this line: char s1[] = "password", s2[];
you'll probably get an unknown array size for s2[]

and i assume you know you have to declare x as something (bool?)

take the terminator off the "if..." statement... but you knew that ;-)

i guess you can initialize s2[] to a known string value just for comparison
 
Old 03-10-2003, 10:05 PM   #19
Randall
Member
 
Registered: Oct 2001
Location: Ontario, Canada (for now, i'm from NJ )
Distribution: Redhat 7.2
Posts: 106

Original Poster
Rep: Reputation: 15
Man that is Genius, using the switch function to handle the four different directions apropriately!!. I would never have thought of it. well atleast i learned how to use the compare string function.


this is one of the best places to get suggestions!

thanks guys
 
  


Reply



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
storing 5 chars into an int in C++? jwn7 Programming 28 05-30-2005 06:54 AM
[php] comparing found username with string Erhnam Programming 4 03-15-2005 09:34 PM
Storing Strings ToothlessRebel Programming 4 09-05-2004 03:16 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
Storing /home in CVS Cyth Linux - General 2 01-03-2003 03:10 AM

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

All times are GMT -5. The time now is 09:13 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