473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

To Lew or any of the other regulars. I hope this isn't an off topic troll thread -(

I want to make a comment on the following url on this forum.

http://groups.google.com/group/comp....3c48178ecd3dd6

The comment revolves around the following the solution to a permute
problem posted by Lew:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void rotate(unsigned length, char *string)
{
char save;

save = *string;
while(--length)
{
*string=*(string+1);
++string;
}
*string = save;

}

void permute(unsigned length, char *string, unsigned depth)
{

if (length == 0)
printf("%s\n",string-depth);
else
{
unsigned count;
for (count = length ; count 0; --count)
{
permute(length-1,string+1,depth+1);
rotate(length,string);
}
}

}

int main(int argc, char **argv)
{
while (--argc)
{
char *source = malloc(strlen(*++argv)+1);

if (source)
{
strcpy(source,*argv);
printf("\nPermuting \"%s\"\n",source);

permute(strlen(source),source,0);

free(source);
}
}
return EXIT_SUCCESS;

}
I'll admit, the first time I saw this, I didn't have a clue what was
going on. Even after stepping through the code via the gnu debugger, I
had no clue. It was during my darkest hour that I discovered the
significance of backtrace and the difference between step-in and
step-out on my debugger. I'll have to admit, that was quite the
experience.

So Lew, or anyone else here. Do you have any more quality lines of c
code that you wish to share with us?

Chad

Jul 25 '06 #1
2 1056
"Chad" <cd*****@gmail.comwrites:
I want to make a comment on the following url on this forum.

http://groups.google.com/group/comp....3c48178ecd3dd6
[...]

That's fine, but it would have been better just to post a followup on
that thread.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 25 '06 #2

Chad wrote:
I want to make a comment on the following url on this forum.

http://groups.google.com/group/comp....3c48178ecd3dd6

The comment revolves around the following the solution to a permute
problem posted by Lew:

#include <stdio.h>
[snip rest of code]
I'll admit, the first time I saw this, I didn't have a clue what was
going on.
Actually, that's one of the reasons that I felt safe in posting it. It
works, but is cryptic enough that a newbie would have trouble passing
it off as his own.
Even after stepping through the code via the gnu debugger, I
had no clue. It was during my darkest hour that I discovered the
significance of backtrace and the difference between step-in and
step-out on my debugger. I'll have to admit, that was quite the
experience.
Yes, recursion can be a really puzzling technique.
So Lew, or anyone else here. Do you have any more quality lines of c
code that you wish to share with us?
I can't claim /quality/ lines of C code (<grin>); I'm just a guy who
writes programs for a living.

OTOH, many regulars here have contributed code samples, fragments, and
prototypes to the newsgroup. They usually come out in response to
interesting problems and unusual challenges. There are probably a
boatload of examples of quines and of recursive "integer to character"
samples in Google's archive. Just keep watching the group, and you'll
see more code.

--
Lew Pitcher
(unsigned until I get a few things fixed)

Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: nobody | last post by:
This article is posted at the request of C.W. Yang who asked me to detail my opinion of Lisp, and for the benefit of people like him, who may find themselves intrigued by this language. The...
109
by: MSG | last post by:
Michel Bardiaux <michel.bardiaux@peaktime.be> wrote in message news:<G4idnfgZ0ZfCWbrdRVn2jQ@giganews.com>... > Mark Shelor wrote: > > > > > OK, Sidney, I am considering it. I can certainly...
33
by: Chris Croughton | last post by:
I notice the real reason for not posting "off-topic" here is that the result will be a long thread on whether the matter is off-topic or not -- caused by the very people who claim that they don't...
59
by: Alan Silver | last post by:
Hello, This is NOT a troll, it's a genuine question. Please read right through to see why. I have been using Vusual Basic and Classic ASP for some years, and have now started looking at...
19
by: sasan3 | last post by:
Every thread I start goes out on a tangent simply because some of you people are not reading my posts carefully: Here is the phrase I am proposing for inclusion in the FAQ: "to existing...
49
by: nroberts | last post by:
In the faq for this group: Q: What's the correct declaration of main()? A: There are two valid declarations: int main(void) int main(int argc, char **argv) although they can be written...
18
by: strangerdream | last post by:
I'm a lurker here, and I do not find any female regulars here in c.l.c. Is it something thats got to do with their genes?
31
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I modify the current browser window?...
96
by: zzbbaadd | last post by:
What's with the index() function of lists throwing an exception on not found? Let's hope this is rectified in Python 3. If nothing else, add a function that doesn't throw an exception. There are a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.