source: trunk/src/emx/testcase/tools/permutatestring.c@ 2309

Last change on this file since 2309 was 1533, checked in by bird, 21 years ago

initial coding.

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1/* $Id: permutatestring.c 1533 2004-10-01 03:47:04Z bird $ */
2/** @file
3 *
4 * permutates the caseness of a string.
5 *
6 * Copyright (c) 2004 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of InnoTek LIBC.
10 *
11 * InnoTek LIBC is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * InnoTek LIBC is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with InnoTek LIBC; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#include <stdio.h>
28#include <string.h>
29#include <ctype.h>
30
31/**
32 * "ab":
33 * "ab"
34 * "aB"
35 * "AB"
36 * "Ab"
37 */
38
39
40static void permuate(char *psz, char *pch)
41{
42 char ch = *pch;
43 if (!ch)
44 return;
45 if (toupper(ch) != ch)
46 {
47 *pch = toupper(ch);
48 printf("%s\n", psz);
49 permuate(psz, pch + 1);
50 *pch = ch;
51 }
52 else if (tolower(ch) != ch)
53 {
54 *pch = tolower(ch);
55 printf("%s\n", psz);
56 permuate(psz, pch + 1);
57 *pch = ch;
58 }
59
60 permuate(psz, pch + 1);
61}
62
63int main(int argc, char **argv)
64{
65 int i;
66
67 for (i = 1; i < argc; i++)
68 {
69 char *psz = strdup(argv[i]);
70 strlwr(psz);
71 printf("%s\n", psz);
72 permuate(psz, psz);
73 }
74 return 0;
75}
76
Note: See TracBrowser for help on using the repository browser.