Initialize char **

R

rasika

I have a structure
typedef struct m
{
char *name,
char **alais;
}mystruct;

The way I have initialised name field of the struct i want to intialise
the alais field to { "geeta", NULL } char array .
So how do i Do it?

mystruct a={
name:"myname",
};
 
A

Ahmed S. Badran

rasika said:
I have a structure
typedef struct m
{
char *name,
char **alais;
}mystruct;

The way I have initialised name field of the struct i want to
intialise the alais field to { "geeta", NULL } char array .
So how do i Do it?
Not sure I understand you, but any string in your code is null terminated,
i.e.

char *t="yourname";

t actually points to a null terminated string, so you already have a null
there.
 
V

Vijay Kumar R Zanvar

rasika said:
I have a structure
typedef struct m
{
char *name,
char **alais;
}mystruct;

The way I have initialised name field of the struct i want to intialise
the alais field to { "geeta", NULL } char array .
So how do i Do it?

mystruct a={
name:"myname",
};

F:\Vijay\C> type howto.c
#include <stdio.h>
#include <stdlib.h>

typedef struct m
{
char *name;
char **alais;
}mystruct;

mystruct a={
.name= "myname",
.alais= (char *[]) { "Geeta", "Seeta", NULL }
/* I would want to know if this casting is correct! */
};

int
main ( void )
{
int i = 0;

printf ( "Name: %s\n", a.name );
printf ( "Alais: \n" );
while ( a.alais )
printf ( "Name: %s\n", a.alais[i++] );
return EXIT_SUCCESS;
}

F:\Vijay\C> gcc -std=c99 -Wall howto.c
F:\Vijay\C> a.exe
Name: myname
Alais:
Name: Geeta
Name: Seeta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top