linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* *w[1]++ = *[k[1]++; does not work .. ?
@ 2003-02-23 17:37 J.
  2003-02-23 19:30 ` Elias Athanasopoulos
  2003-02-24 16:02 ` *w[1]++ = *[k[1]++; does not work .. ? IVAN DE JESUS DERAS TABORA
  0 siblings, 2 replies; 6+ messages in thread
From: J. @ 2003-02-23 17:37 UTC (permalink / raw)
  To: linux-c-programming

Hello...

I am trying to copy a string into the first element of an array of char
pointers.

I can print char by char like this: printf("%c", *w[1]++);
but I can not copy char by char like this: *w[1]++ = *k[1]++;

I dont understand ? If I can print it, it should also copy ..

Strangly enough the compiler does not complain.

I have inserted a small illustrative example in this e-mail.

/* To illustrate the difference: This works */
#include <stdio.h>
#include <string.h>

int main(void) {
 char *w[1];
 char str[] = "jehova";

 w[1] = strdup(str);

 while(*w[1] != '\0')
  printf("%c", *w[1]++);

 printf("\n");
 return 0;
}

/* But this does not work */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
 char *w[1];
 char *k[1];
 char str[] = "jehova";

 w[1] = strdup(str);
 k[1] = calloc(strlen(str) + 1, sizeof(char));

 while(*w[1] != '\0')
  *k[1]++ = *w[1]++; 

 printf("%s\n", w[1]);
 return 0;
}

Can someone explain what I am doing wrong ?

Thankx a lot,...

J.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-02-24 16:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-23 17:37 *w[1]++ = *[k[1]++; does not work .. ? J.
2003-02-23 19:30 ` Elias Athanasopoulos
2003-02-24  7:55   ` J.
2003-02-24  9:05     ` Elias Athanasopoulos
2003-02-24  9:35       ` *w[1]++ = solved... thnkx... ? J.
2003-02-24 16:02 ` *w[1]++ = *[k[1]++; does not work .. ? IVAN DE JESUS DERAS TABORA

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).