Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
scope q
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Barry Schwarz, post: 2466943"] All your subroutines are at file scope. You don't have a choice about this since C does not allow nested functions. If the prototype for swap() is really inside the body of main(), then when you call it inside permute(), the compiler will not know what types of arguments it takes or what kind of value it returns. In C99 a diagnostic is required. In C89, the compiler must assume it returns an int, which is incorrect in this case. Many compilers will also generate an discretionary diagnostic about the missing prototype. If you move the code for swap() before the code for permute(), the problem goes away. The oft recommended approach here is to put your prototypes at file scope; it's just cleaner all around. Since permute() receives a pointer to the string (as opposed to the string itself), it can update the string in place. You don't need to pass the length (though it is more efficient in my opinion) since permute could figure it out (e.g., strlen). Whether or not your function can generate a permutation with no other knowledge is an algorithm question. I expect the answer can be found in Knuth's masterpiece. Remove del for email [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
scope q
Top