Brute force with NULLs [closed] - c

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does anyone know how to write a brute force program where if, say, the lenght is 4, in the beginning, the string would be a\0\0\0, b\0\0\0,..., ab\0\0 and so on, ie keeping its NULLs.
My question is for a password cracking homework.
Thanks

Here's an algorithm:
memset it all to null.
Increment the first character.
Repeat step 2 until the first character overflows.
Increment the second character
Go back to step 2 and repeat until the second character overlows.
Increment the third character.
You get the idea...
I leave the implementation up to you. It's your homework.

Related

If statement and sequential execution [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I have a very short (and pretty much noob) question. I have a function that includes:
void function(int x)
{
x = 3;
if (x == 4)
printf("HI!");
x = 4;
}
Will the word HI! be printed? In other words, is a C program read sequentially or not?
Thanks a lot!
No, the code compiles to a sequence of instructions which happen sequentially one after the other. The comparison to 4 will always before the assignment x = 4. So it will be false.
This type of order is guaranteed when you are dealing with a single thread. When you have multiple threads you can get strange results and race-conditions unless you are careful.
It will not be printed. The line above is what matters of course.

C/C++: Is there a specific reason why "void" was not simply defined as "typedef struct{} void" (i.e. an empty struct) with appropriate casting rules? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
As an aside: Such a standard typedef would have help reduce the number of reserved words in C/C++, and relegated void to a simple type declaration, e.g. in <stddef.h>. (c.f. SRB in AB33/Mar 1972 - PDF=7kB)
That's pretty speculative. But one good reason is because void is not an empty value; it's the absence of a value. For instance, a function with a signature of int f(void) takes zero arguments, not one.

C if else condition [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In C if i have only one line in the if condition then can i combine it into one line to reduce the size of code. The size of code is long so I intend to take this step to reduce size of code. Should I should I not? Is it a good programming practice?
It makes no sense to be concerned about the size of the sources at the point of sacrificing readability, especially since sources are extremely small compared to almost any kind of other data that our computers usually process/store (e.g. the bzipped sourced of the Whole Firefox are 85 MB - smaller than any medium-length video). Also, omitting a newline won't change the compilation times of a millisecond.
So, if you prefer one-line ifs for your own stylistic reasons it's fine (although it's often frowned upon), but for saving a few bytes it makes no sense at all.
Actually if the code is long then it's not good programming practice as that code will not be as readable.
so it's better to use if else syntax to make your code readable

Increment a variable to be compared inside an if [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
if (++bufCnt >= smenu->bufSize) //line1
if (bufCnt++ >= smenu->bufSize) //line2
In line1 bfrCnt is first incremented and then compared. In line2 it is first compared and then incremented. Is this correct?
Correct.
In both case you increase bufCnt.
But without else if you increase bufCnt two times.
Yes,
In line1 bfrCnt is first incremented and then compared.
In line2 it is first compared and then incremented.
Your question is not having the quality when it is compared to the other questions in this site. That is why you are getting down votes.
So when ever you are posting a question, make sure it is having enough standard.

Does C require that variables are declared at start of scope? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
The C language requires that all variables used in the program should be declared before any other statements.
Why was this of significance? Was it for readability? If it was for readability, then why don't other languages follow the same rule?
I personally prefer declaring all my variables at the very start.
Moderators: Please delete if this is off-topic or already been asked. I was just keen to know improve my knowledge. Thanks.
Like other people said in comments now it's not mandatory anymore. Anyway it wasn't for readability. C is a very old language and one of its peculiar features is that a C file can be compiled with just one parsing. I think that the earliest version of the language made the choice to declare variable at the beginning for simplify the parsing

Resources