Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Mon, 23 Jul 2012 21:51:17 -0500 |
| Message-ID | <500E0DA2.3075@mindspring.com> (permalink) |
| Date | Mon, 23 Jul 2012 22:51:14 -0400 |
| From | pete <pfiland@mindspring.com> |
| Reply-To | pfiland@mindspring.com |
| Organization | PF |
| X-Mailer | Mozilla 3.04Gold (WinNT; I) |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.c |
| Subject | Re: How to passing multidimesional array of string to function? |
| References | <500d3b6c$0$17953$4fafbaef@reader1.news.tin.it> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 152 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.156.228.78 |
| X-Trace | sv3-UTbn9k3u236WGiKMKac7fOqWMG4UCLtXcpaj6PRCDekoUyw9Zs/2JFun49sFzr2AKPp1AUHe57onD3n!t7xU6ZBgDLdjB9MYPMGBk5j8r8G/nCeLPo1KkcWAgWuj76HXh1oHx5mkz5PTJxmFMZRBPSEu1Gk4!xaI9slir7g== |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 5328 |
| Xref | csiph.com comp.lang.c:23642 |
Show key headers only | View raw
Alter wrote:
>
> Hi all
>
> How to pass a multidimensional array of string to a function?
>
> Thanks in advance
>
> Cheers
/* BEGIN new.c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SORT_FUNCTIONS \
no_sort, "Original order of the test arrays:", \
slsort, "Nonstable simple selection sort:", \
i_sort, "Stable insertionsort:", \
qsort, "Standard library qsort;\n" \
"unspecified ordering of equal keys:"
#define NUMBERS \
"zero","one","two","three","four","five", \
"six","seven","eight","nine","ten"
#define NMEMB(A) (sizeof (A) / sizeof *(A))
int comp(const void *a, const void *b);
void no_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
void slsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
void i_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
int
main(void)
{
size_t element, sort;
struct sf {
void (*func)(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
const char *description;
} s_F[] = {SORT_FUNCTIONS};
const char numbers[][sizeof "three"] = {NUMBERS};
char array[NMEMB(numbers)][sizeof "three"];
puts("\n/* BEGIN output from new.c */\n\n"
"Arrays of (char [sizeof \"three\"]),\n"
"are being sorted by string length.\n");
for (sort = 0; sort != NMEMB(s_F); ++sort) {
memcpy(array, numbers, sizeof array);
s_F[sort].func(array, NMEMB(array), sizeof*array, comp);
puts(s_F[sort].description);
for (element = 0; element != NMEMB(array); ++element) {
puts(array[element]);
}
putchar('\n');
}
puts("/* END output from new.c */");
return 0;
}
int
comp(const void *a, const void *b)
{
const char (*const aaa)[sizeof "three"] = a;
const char (*const bbb)[sizeof "three"] = b;
const char *aa = *aaa;
const char *bb = *bbb;
while (*aa != '\0' && *bb != '\0') {
++aa;
++bb;
}
return *bb != '\0' ? -1 : *aa != '\0';
}
void
no_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
base, nmemb, size, compar;
}
void
slsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
size_t tail;
unsigned char *array, *first, *middle, *end, swap;
if (nmemb-- > 1) {
end = base;
do {
array = end;
end += size;
first = middle = end;
tail = nmemb;
while (--tail != 0) {
middle += size;
if (compar(first, middle) > 0) {
first = middle;
}
}
if (compar(array, first) > 0) {
do {
swap = *first;
*first++ = *array;
*array++ = swap;
} while (array != end);
}
} while (--nmemb != 0);
}
}
void
i_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
unsigned char *array, *low, *high, *p1, *p2, swap;
if (nmemb-- > 1) {
array = base;
do {
low = array;
high = low + size;
array = high;
while (compar(low, high) > 0) {
p1 = high;
p2 = low;
do {
swap = *p1;
*p1++ = *p2;
*p2++ = swap;
} while (p2 != high);
if (low == base) {
break;
}
high = low;
low -= size;
}
} while (--nmemb != 0);
}
}
/* END new.c */
--
pete
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to passing multidimesional array of string to function? "Alter" <no@alt.invalid> - 2012-07-23 13:53 +0200
Re: How to passing multidimesional array of string to function? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-23 08:54 -0400
Re: How to passing multidimesional array of string to function? "Alter" <no@alt.invalid> - 2012-07-24 19:08 +0200
Re: How to passing multidimesional array of string to function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-24 18:28 +0100
Re: How to passing multidimesional array of string to function? "Alter" <no@alt.invalid> - 2012-07-24 21:40 +0200
Re: How to passing multidimesional array of string to function? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-07-24 13:16 -0700
Re: How to passing multidimesional array of string to function? Fred K <fred.l.kleinschmidt@gmail.com> - 2012-07-24 13:22 -0700
Re: How to passing multidimesional array of string to function? Fred K <fred.l.kleinschmidt@gmail.com> - 2012-07-24 13:22 -0700
Re: How to passing multidimesional array of string to function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-24 22:19 +0100
Re: How to passing multidimesional array of string to function? Stephen Sprunk <stephen@sprunk.org> - 2012-07-24 19:45 -0500
Re: How to passing multidimesional array of string to function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-24 22:07 +0100
Re: How to passing multidimesional array of string to function? Ike Naar <ike@iceland.freeshell.org> - 2012-07-24 18:16 +0000
Re: How to passing multidimesional array of string to function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-23 14:07 +0100
Re: How to passing multidimesional array of string to function? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-07-23 08:05 -0700
Re: How to passing multidimesional array of string to function? pete <pfiland@mindspring.com> - 2012-07-23 22:51 -0400
Re: How to passing multidimesional array of string to function? Varun Tewari <tewari.varun@gmail.com> - 2012-07-24 10:21 -0700
Re: How to passing multidimesional array of string to function? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-24 13:50 -0400
Re: How to passing multidimesional array of string to function? C3PO <nospam@nospam.com> - 2012-07-28 20:41 +0000
Re: How to passing multidimesional array of string to function? Keith Thompson <kst-u@mib.org> - 2012-07-28 15:04 -0700
Re: How to passing multidimesional array of string to function? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-28 22:07 -0400
Re: How to passing multidimesional array of string to function? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-07-29 11:33 +0300
Re: How to passing multidimesional array of string to function? aftnix <aftnix@gmail.com> - 2012-07-26 13:35 -0700
Re: How to passing multidimesional array of string to function? Barry Schwarz <schwarz45@yahoo.com> - 2012-07-27 15:05 -0700
csiph-web