password

This is a discussion on password within the C Programming forums, part of the General Programming Boards category; i just want to make program that accepts our string as password.but finally at the end that program will show ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    3

    password

    i just want to make program that accepts our string as password.but finally at the end that program will show that password

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Well, good luck with that.
    My best code is written with the delete key.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    1) Make an attempt
    2) Show us the code
    3) Explain where you're stuck and what you've tried, what research you've done
    4) Receive help
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    As you wish, master.

    Code:
    #include <iostream.h>
    int main(void)
    {
        char *password;
        scanf("%s", password);
        if(password != "our string") printf("Not accepted!");
        /* end of program */
        else printf("that password");
        return 0;
    }
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    I sure hope jafet is being ironic with that post...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Quote Originally Posted by jafet
    Code:
    #include <iostream.h>
    Wrong library to be using with printf() and scanf(). Try stdio.h instead.

    Quote Originally Posted by jafet
    Code:
        char *password;
        scanf("%s", password);
    You need to either allocate memory to store the string, or store the string on the heap using a predefined array.

    Allocating to the stack:
    Code:
    char *szPassword = (char *)malloc(sizeof(char) * 256);
    // ..
    free(szPassword);
    Storing on the heap:
    Code:
    char szPassword[256];
    Quote Originally Posted by jafet
    [CODE]
    Code:
        if(password != "our string") printf("Not accepted!");
        /* end of program */
        else printf("that password");
    You cannot compare strings (which are arrays of characters) using ==, !=, >, <, or any combination of these. You must use the function strcmp() (or a variation), which returns 0 upon success.

    Code:
    if(strcmp(password, "our string") != 0) printf("Not accepted!");
    else printf("that password");
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    I think all of those errors were intentional, Okiesmokie.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Quote Originally Posted by SlyMaelstrom
    I think all of those errors were intentional, Okiesmokie.
    x_x Thought that was the original poster replying to:
    1) Make an attempt
    2) Show us the code
    3) Explain where you're stuck and what you've tried, what research you've done
    4) Receive help
    What a waste of a long helpful post
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    3
    thank you jafet

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Quote Originally Posted by radhika
    thank you jafet
    Hmmm... did you even bother reading the other posts or did you just scan the whole thing for code you can steal?

    Oh well... he's probably long gone on his way to failing his programming project.
    Sent from my iPadŽ

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Quote Originally Posted by Okiesmokie
    Allocating to the stack:
    Code:
    char *szPassword = (char *)malloc(sizeof(char) * 256);
    // ..
    free(szPassword);
    Storing on the heap:
    Code:
    char szPassword[256];
    You got that backwards by the way, the stack is used for predifined variables in code, dynamicly allocated memory is in the heap. Both of those use the stack, it's just that one is pointing to memory that is dynamicly allocated, the other is to part of the stack.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Not to mention that you don't need to cast malloc() and that sizeof(char) is always 1.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 06:20 AM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 02:42 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM

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