473,498 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Initialize char **

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",
};
Nov 14 '05 #1
4 2958
rasika wrote:
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.
mystruct a={
name:"myname",
};


Nov 14 '05 #2
rasika wrote:
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.
mystruct a={
name:"myname",
};


Nov 14 '05 #3

"rasika" <ra******@hotmail.com> wrote in message news:ab******************************@localhost.ta lkaboutprogramming.com...
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[i] )
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

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05 #4

"rasika" <ra******@hotmail.com> wrote in message news:ab******************************@localhost.ta lkaboutprogramming.com...
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[i] )
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

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

74
42912
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
11
5579
by: Der Andere | last post by:
I want to initialize unsigned int and unsigned char with their maximum value. Just for being sure: Does unsigned int i = pow(256,sizeof(i))-1; unsigned char c = pow(256,sizeof(c))-1; always...
4
3494
by: qazmlp | last post by:
// Test.C Line-300: namespace Line-301: { Line-302: std::vector<std::string> vecaNS ; Line-303: } The 'SUN Forte 7 C++ Compiler' reports the following warning for the above code:...
6
2726
by: Kai Wu | last post by:
#include <string.h> #include <fstream> #include <time.h> typedef unsigned char BYTE; struct Dex { BYTE status; struct timeval timestamp; }; int main(){
9
26969
by: Niels Dekker - no reply address | last post by:
Are all the following initializations semantically equivalent? wchar_t a = {L'\0'}; wchar_t b = {'\0'}; wchar_t c = {0}; wchar_t d = {}; If so, why don't we all use an empty initializer...
1
4683
by: DC | last post by:
Hi, I am programming a windows service and all went well until I needed to use a simple array of chars which I initialize like this: char test = new char {'\x002F', '\x005E'}; Immediatly...
10
2991
by: wenmang | last post by:
hi, I have following: struct array1 { int id; char *name; }; struct array2 {
15
26390
by: thinktwice | last post by:
char a = { 0 } is it ok?
1
4341
by: BrandonG | last post by:
I am working on a JNI project, the env->NewStringUTF function will only accept a const char as a parameter. The trouble I am having is that within the native method I need to modify the string...
4
6127
by: June Lee | last post by:
what is it means by {0}, is that means initialize a struct to NULL? ne_uri uri = {0}; typedef struct { char *scheme; char *host, *userinfo; unsigned int port; char *path, *query, *fragment;...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.