i just want to make program that accepts our string as password.but finally at the end that program will show that password
i just want to make program that accepts our string as password.but finally at the end that program will show that password
Well, good luck with that.
My best code is written with the delete key.
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.
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;}
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.
Wrong library to be using with printf() and scanf(). Try stdio.h instead.Originally Posted by jafet
You need to either allocate memory to store the string, or store the string on the heap using a predefined array.Originally Posted by jafet
Allocating to the stack:
Storing on the heap:Code:char *szPassword = (char *)malloc(sizeof(char) * 256); // .. free(szPassword);
Code:char szPassword[256];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.Originally Posted by jafet
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."
I think all of those errors were intentional, Okiesmokie.
Sent from my iPadŽ
x_x Thought that was the original poster replying to:Originally Posted by SlyMaelstrom
What a waste of a long helpful post1) 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
"There are three kinds of people in the world...
Those that can count and those that can't."
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?Originally Posted by radhika
Oh well... he's probably long gone on his way to failing his programming project.
Sent from my iPadŽ
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.Originally Posted by Okiesmokie
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.
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.