On Wed, 18 Oct 2000, Andy wrote:

> dear all,
> saya mengalami kesulitan dalam menggunakan call by refeence di c-nya linux :)
> berikut contoh snippet kode
> 
> #include <stdlib.h>
> #include <stdio.h>
> 
> int xorz[9]={34,56,22,41,23,54,12,64,23};
> 
> void callbyreference2(char & p)
> {
> char * strz;
> int i;
> i=0;
> strz=*p;
> while (*strz){
> p[i] = (p[i] ^ (xorz[i]+i));
> strz++;
> i++;
> }
> return ;
> }
> 
> void callbyreference(int & p)
> {
> callbyreference2(p);
> return ;
> }
> 
> void main(void)
> {
> int x = 10;
> char * coba = "teststring";
> callbyreference(coba);
> puts(coba);
> return;
> }

Programnya diganti dikit, biar ngeliatnya gampang.
#include <stdlib.h>
#include <stdio.h>

void callbyreference(char **p) {
  char *strz;
  strz = *p;
  while (*strz) {
    *strz = 'x';
    strz++;
  }
  return ;
}

int main(void) {
  char *coba = malloc(sizeof(char) * 11);
  strcpy(coba, "teststring"); 
  callbyreference(&coba);
  puts(coba);
  /* perlu free(coba) di sini?
  // atau coba = null ? ;-)
  */
}

Oki

--
Linux programs already can run on HP-UX systems using HP's PA-RISC chip, but
they must go through a technical reworking process called recompilation.
                        http://news.cnet.com/news/0-1003-200-2495414.html


--------------------------------------------------------------------------------
Utk berhenti langganan, kirim email ke [EMAIL PROTECTED]
Informasi arsip di http://www.linux.or.id/milis.php3
Pengelola dapat dihubungi lewat [EMAIL PROTECTED]

Kirim email ke