From: "J." <mailing-lists@xs4all.nl>
To: linux-c-programming@vger.kernel.org
Subject: *w[1]++ = *[k[1]++; does not work .. ?
Date: Sun, 23 Feb 2003 18:37:08 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.21.0302231825450.10716-100000@hestia> (raw)
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.
next reply other threads:[~2003-02-23 17:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-23 17:37 J. [this message]
2003-02-23 19:30 ` *w[1]++ = *[k[1]++; does not work .. ? 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
-- strict thread matches above, loose matches on Subject: below --
2003-02-24 8:21 Alvarez Alberto-AALVARB1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.21.0302231825450.10716-100000@hestia \
--to=mailing-lists@xs4all.nl \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).