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",
}; 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", };
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", };
"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/
"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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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);
----------
|
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...
|
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:...
|
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(){
|
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...
| |
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...
|
by: wenmang |
last post by:
hi,
I have following:
struct array1
{
int id;
char *name;
};
struct array2
{
|
by: thinktwice |
last post by:
char a = { 0 }
is it ok?
|
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...
|
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;...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |