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 2948
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |