Thread: How best to pass integer array from one c program to another

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    3

    How best to pass integer array from one c program to another

    Hello,

    My friend and I are working on a project that involves grabbing data off another device via serial port and displaying it to a screen. I am responsible for accepting the processed data and displaying it to some graphical window.

    Saying that I have a simple program that right now can display graphics to a window using glade. However, I am trying now to work on the piece that can accepts the data. I have been looking into IPC, socket and now czmq possible solutions. Currently, the most ideal solution involves accepting an array, possible multidimensional array or some other data structure.

    My more specific question is what is the best or easiest way to accept this data from one program to another? As of now I am still researching czmq but perhaps someone has a better solution or even better some code examples.

    Thanks,

    Joe

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,602
    What type of devices are you dealing with?

    What type and how much data are you going to be transmitting?

    Jim

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    > My more specific question is what is the best or easiest way to accept this data from one program to another?
    A pipe is usually simplest.

    All you need (at the command line) say is
    producer | consumer

    Whatever producer writes to stdout, consumer can read from stdin.

    How you format the data is up to you, so long as both agree what it is.

    Maybe something simple like
    Code:
    printf("Rows=%d, Cols=%d\n", rows, cols );
    for ( r = 0 ; r < rows ; r++ ) {
      for ( c = 0 ; c < cols ; c++ ) {
        printf("%d ", array[r][c] );
      }
      printf("\n");
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-24-2015, 07:43 AM
  2. Replies: 7
    Last Post: 10-07-2013, 05:51 PM
  3. Replies: 3
    Last Post: 05-09-2012, 06:41 AM
  4. Replies: 1
    Last Post: 10-21-2007, 07:44 AM
  5. Replies: 3
    Last Post: 04-02-2002, 01:39 PM