LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-22-2010, 11:04 PM   #1
is noname
LQ Newbie
 
Registered: Dec 2009
Posts: 11

Rep: Reputation: 0
Thumbs up pointer in C language


haii ,guyss ..
i am beginner in C language ..please help me .
i see the code :

typedef struct {
int a ;
char *b ;
int *c ;
}EXP2 ;

typedef struct xx {
int a ;
char *s ;
EXP2 *exp2 ;
struct xx *next ;
}EXP1 ;

int main () {
}

Last edited by is noname; 03-22-2010 at 11:27 PM. Reason: many post ..
 
Old 03-22-2010, 11:12 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I'm not at all sure what your question is...
... but here's a simple example that might answer at least part of your question(s):
Code:
#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct 
{
  int a ;
  char *b ;
  int *c ;
}
  EXP2;

typedef struct xx 
{
  int a ;
  char *s ;
  EXP2 *exp2 ;
  struct xx *next;
}
  EXP1;

int 
main (int arg ,  char *argv[]) 
{
}#include <stdio.h>
#include <string.h>
#include <malloc.h>

struct x
{
  int a ;
  char *b ;
  int *c ;
};

struct xx 
{
  int a ;
  char *s ;
  struct x *exp2 ;
  struct xx *next;
};

int 
main (int arg ,  char *argv[]) 
{
  struct xx *mystruct = NULL;

  printf ("Allocating data...\n");
  mystruct = calloc (1, sizeof (struct xx));
  printf ("mystruct->a= %d, mystruct->s= %s...\n", mystruct->a, mystruct->s);

  printf ("Populating data...\n");
  mystruct->a = 2;
  mystruct->s = argv[0];
  mystruct->next = mystruct;
  printf ("mystruct->a= %d, mystruct->s= %s...\n", mystruct->a, mystruct->s);
  printf ("mystruct->next->a= %d, mystruct->next->s= %s...\n", 
    mystruct->next->a, mystruct->next->s);

  free (mystruct);
  return 0; 
}
Quote:
Allocating data...
mystruct->a= 0, mystruct->s= (null)...
Populating data...
mystruct->a= 2, mystruct->s= x...
mystruct->next->a= 2, mystruct->next->s= x...
<= I called the program "x", which is why "argv[0]" is "x"...

Last edited by paulsm4; 03-22-2010 at 11:24 PM.
 
0 members found this post helpful.
Old 03-23-2010, 09:38 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
So dude - I'm glad you solved it ... but what were you asking? Twice?

Inquiring minds want to know
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to pointer segmentation fault Guilherme Programming 7 06-28-2009 09:47 AM
Good linux chinese language language program? darsunt Linux - Software 1 04-10-2009 12:06 PM
pass pointer,, return pointer??? blizunt7 Programming 3 07-23-2005 01:36 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration