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 2950
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |