Code examples of manipulating an array of pointers. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLIST 10 struct ipList { int id; char *name; char *ip; }; struct ipList **getList( void ); void printList( struct ipList **list ); int main( void ) { struct ipList **theList; theList = getList( ); printList( theList ); return 0; } struct ipList **getList( void ) { struct ipList **list; int i; list = malloc( MAXLIST * sizeof( struct ipList * ) ); i = 0; while ( i < MAXLIST ) { list[ i ] = malloc( sizeof( struct ipList ) ); list[ i ]->id = i; list[ i ]->name = "citibank.co.cx"; list[ i ]->ip = "209.249.147.15"; i++; } return ( list ); } void printList( struct ipList **list ) { int i = 0; while ( i < MAXLIST ) { printf( "%s - %s", ( list[ i ]->name ), ( list[ i ]->ip ) ); i++; } }

we can change the function getList slightly:

struct ipList **getList( void ) { static struct ipList *list[ MAXLIST ]; int i; //list = malloc( MAXLIST * sizeof( struct ipList * ) ); i = 0; while ( i < MAXLIST ) { list[ i ] = malloc( sizeof( struct ipList ) ); list[ i ]->id = i; list[ i ]->name = "citibank.co.cx"; list[ i ]->ip = "209.249.147.15"; i++; } return ( list ); }

or we could have the main array created in main like this:

#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLIST 10 struct ipList { int id; char name[ 35 ]; char ip[ 15 ]; }; void getList( struct ipList *list[ ] ); struct ipList *makeIP( void ); void printList( struct ipList *list[ ] ); int main( void ) { struct ipList *theList[ MAXLIST ]; getList( theList ); printList( theList ); return 0; } void getList( struct ipList *list[ ] ) { int i = 0; while ( i < MAXLIST ) { list[ i ] = makeIP( ); list[ i ]->id = i; strcpy( ( list[ i ]->name ), "citibank.co.cx" ); strcpy( ( list[ i ]->ip ), "209.249.147.15" ); i++; } } struct ipList *makeIP( void ) { struct ipList *temp; temp = malloc( sizeof( struct ipList ) ); return ( temp ); } void printList( struct ipList *list[ ] ) { int i = 0; while ( i < MAXLIST ) { printf( "%s - %s", ( list[ i ]->name ), ( list[ i ]->ip ) ); i++; } }

posted by dharh 9:59 PM Oct 2nd, 2006

Here's a cool report from Gina Trapani over at lifehacker about Yahoo! Open Hack Day '06. It's pretty interesting. You could say Yahoo! Open Hack Day is like Google Code Jam.

posted by dharh 12:56 PM Oct 2nd, 2006

Part of the passion in my life, besides life itself, is programming and computers. I especially like the idea of smart computing through smart programs and smart OSes. Which is what I want to focus on in my career, creating intelligence to various degrees to help create better and more efficient user experiences using computers.

Bellow is a table of various code snippets and articles organized by language.

C/C++ C# Java JavaScript
Returning an Array of Pointers javascript trim

15 Exercises for Learning a new Programming Language

This is an exercise to both learn a language, but also to compare different languages. The original idea can be found here.

  1. Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).
  2. Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.
  3. Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.
  4. Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity Write a program that will accept all values in appropriate units (Don't worry about unit conversion) If number is < 2100, display Laminar flow, If it's between 2100 and 4000 display 'Transient flow' and if more than '4000', display 'Turbulent Flow' (If, else, then...)
  5. Modify the above program such that it will ask for 'Do you want to calculate again (y/n), if you say 'y', it'll again ask the parameters. If 'n', it'll exit. (Do while loop)

    While running the program give value mu = 0. See what happens. Does it give 'DIVIDE BY ZERO' error? Does it give 'Segmentation fault..core dump?'. How to handle this situation. Is there something built in the language itself? (Exception Handling)
  6. Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus
  7. Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)
  8. Open a text file and convert it into HTML file. (File operations/Strings)
  9. Time and Date : Get system time and convert it in different formats 'DD-MON-YYYY', 'mm-dd-yyyy', 'dd/mm/yy' etc.
  10. Create files with date and time stamp appended to the name
  11. Input is HTML table, Remove all tags and put data in a comma/tab separated file.
  12. Extract uppercase words from a file, extract unique words
  13. Implement word wrapping feature (Observe how word wrap works in windows 'notepad')
  14. Adding/removing items in the beginning, middle and end of the array.
  15. Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.

C# Java Python
Learn 2 C# 1 Learn 2 Java 1
Learn 2 C# 2
Learn 2 C# 3
Learn 2 C# 4 and 5
Learn 2 C# 6
Learn 2 C# 7
Learn 2 C# 8
Learn 2 C# 9
Learn 2 C# 10
Learn 2 C# 11
Learn 2 C# 12


posted by dharh 2:06 PM Mar 15th, 2006

You can do this by going to your
C:Documents and SettingsUser NameApplication DataMozillaFirefoxProfiles directory. From there it might be either xxxxxxx.defaultchrome or default.xxxchrome. Create/edit the userChrome.css file, then add to it the following code:
/* Make menus disapear */
menubar > menu
{
	display: none !important;
}
You can also just hide specific menu items which you can do using the following code:
/* Hide menu Name */
menulabel="Name" {
	display: none !important;
}

posted by dharh 1:03 PM Feb 6th, 2006

I have been working on, in the last couple weeks, a Java based version of the todo app I created a year ago in Cold Fusion. So far it is still in initial proto phase, i.e. I'm still hobbling together code just so a user can login and see a list of items from their todo list. It is an open source project as soon as im satisfied with a beta version I'll release the source.

posted by dharh 3:27 PM Jul 16th, 2005


« Previous 1 2 3 4
Next »


2011: 5 3 1
2010: 12 9 7 1
2009: 12 11 8 5
2008: 12 5 4 3 2 1
2007: 12 11 10 9 8 7 6 5 4 3 2 1
2006: 12 11 10 9 8 7 6 5 4 3 2 1
2005: 12 10 7 6
2004: 10 9 6 5 4 3 2 1