Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.advocacy > #536171
| From | DFS <nospam@dfs.com> |
|---|---|
| Subject | Feeb, can you improve this simple C code? |
| Newsgroups | comp.os.linux.advocacy |
| Message-ID | <lF%mF.108280$LC2.8395@fx45.iad> (permalink) |
| Organization | blocknews - www.blocknews.net |
| Date | 2019-10-08 08:53 -0400 |
It takes two existing (sorted) char arrays and combines the elements
into a new array.
That's it.
My solution is below. Don't look at it until you've posted yours. Note:
I'm not asking for any sorting, just copying elements into a new data
structure.
You can use these for testing:
char *x[] = {"1","7","D","e","M","o","z"}
char *y[] = {"A","c","p","S","x"}
output would be: {"1","7","D","e","M","o","z","A","c","p","S","x"}
--------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
int i = 0;
void combinearrays(int a, int b, char *x[], char *y[], char *z[]) {
for(i=0;i<a;i++) z[i] = x[i];
for(i=0;i<b;i++) z[i+a] = y[i];
}
void main() {
char *x[] = {"1","7","D","e","M","o","z"};
char *y[] = {"A","c","p","S","x"};
int j = sizeof(x)/sizeof(x[0]);
int k = sizeof(y)/sizeof(y[0]);
char **z = malloc(sizeof(char*) * (j+k));
combinearrays(j,k,x,y,z);
i=0;
while (i<j+k) printf("%s ",z[i++]);
free(z);
exit(0);
}
--------------------------------------------------------------------------
Back to comp.os.linux.advocacy | Previous | Next — Next in thread | Find similar | Unroll thread
Feeb, can you improve this simple C code? DFS <nospam@dfs.com> - 2019-10-08 08:53 -0400
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 06:21 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 07:07 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 14:33 +0000
Re: Feeb, can you improve this simple C code? DFS <nospam@dfs.com> - 2019-10-08 17:10 -0400
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 21:25 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:42 -0700
Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:23 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:27 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 21:38 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:58 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 15:14 -0700
Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:25 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-09 00:58 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 14:51 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 22:19 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 15:36 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 16:00 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-09 07:36 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 15:44 -0700
Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:26 +0000
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-09 08:22 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-09 01:44 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-09 08:29 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 14:44 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <"Steve Carroll"@noSPAM.none> - 2019-10-08 14:51 +0000
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 15:16 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 08:40 -0700
Re: Feeb, can you improve this simple C code? Mel <mel@zzzzz.com> - 2019-10-08 18:11 +0200
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:40 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:55 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 18:38 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 11:56 -0700
Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-08 19:42 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 13:13 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:19 +0000
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:26 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 13:38 -0700
Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:55 +0000
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:12 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:57 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:42 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:27 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 07:53 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 08:09 -0700
Re: Feeb, can you improve this simple C code? Mel <mel@zzzzz.com> - 2019-10-08 18:09 +0200
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:25 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 10:56 -0700
Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 12:11 -0700
memmove( z, x, sizeof x ); Jeff-Relf.Me @. - 2019-10-09 00:56 -0700
Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-10 13:13 -0400
"memcpy()" is a special case INSIDE "memmove()". Jeff-Relf.Me @. - 2019-10-10 11:17 -0700
Re: "memcpy()" is a special case INSIDE "memmove()". Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:27 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-10 21:20 +0000
Re: memmove( z, x, sizeof x ); Siri Cruise <chine.bleu@yahoo.com> - 2019-10-10 15:07 -0700
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:36 +0000
Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-11 09:29 -0400
Re: memmove( z, x, sizeof x ); Siri Cruise <chine.bleu@yahoo.com> - 2019-10-11 08:28 -0700
memmove( z, x, sizeof x ); Jeff-Relf.Me @. - 2019-10-11 10:01 -0700
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:29 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:20 +0000
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 18:22 +0000
Re: memmove( z, x, sizeof x ); chrisv <chrisv@nospam.invalid> - 2019-10-11 13:45 -0500
Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-11 15:46 -0400
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:57 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:31 +0000
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 18:24 +0000
Re: memmove( z, x, sizeof x ); "F. Russell" <frussell@random.info> - 2019-10-11 18:55 +0000
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:16 +0000
Re: memmove( z, x, sizeof x ); "F. Russell" <frussell@random.info> - 2019-10-11 19:29 +0000
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:39 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 09:03 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-10 21:30 +0000
Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:33 +0000
Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:21 +0000
Insane, Animalistic, Immoral, Detached. Jeff-Relf.Me @. - 2019-10-10 15:43 -0700
Asset bubbles make people horny, stupid. Jeff-Relf.Me @. - 2019-10-10 16:04 -0700
Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 16:09 -0700
Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-10 16:28 -0700
Re: Insane, Animalistic, Immoral, Detached. The Right And The Powerful <power2019@gmail.com> - 2019-10-10 18:35 -0500
Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-10 16:47 -0700
Re: Insane, Animalistic, Immoral, Detached. The Right And The Powerful <power2019@gmail.com> - 2019-10-10 20:39 -0500
Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 20:39 -0700
Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-11 08:31 +0000
Re: Insane, Animalistic, Immoral, Detached. chrisv <chrisv@nospam.invalid> - 2019-10-11 08:36 -0500
Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 20:36 -0700
Re: Insane, Animalistic, Immoral, Detached. % <persent@gmail.com> - 2019-10-10 20:41 -0700
Re: Insane, Animalistic, Immoral, Detached. chrisv <chrisv@nospam.invalid> - 2019-10-11 08:53 -0500
Re: Insane, Animalistic, Immoral, Detached. Sergio <invalid@invalid.com> - 2019-10-11 10:14 -0500
csiph-web