Results 1 to 2 of 2

Thread: multi dimensional arrays using C

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Posts
    89

    multi dimensional arrays using C

    Hi, I've been trying to dynamically dimension a multidimensional array using C but I keep getting a compiler error. I've tried going through the help files example, but theres didn't work. Thanks for any help
    PHP Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>

    int rows=3,columns=5;
    void main(void)
    {
      
    float *matrix=NULL;
      
    int i,j;
      
    matrix = (float*)calloc(rowssizeof(float*));

      for (
    i=0i<rows; ++i)
      {
        
    matrix[i] =(float*)calloc(columns,sizeof(float*));
      }
      for (
    i=0i<rowsi++)
      {
        for (
    j=0j<columnsj++)
        {
          
    //matrix[i][j] = i+j;
        
    }
      }
      for (
    i=0i<rows; ++i
      {
        
    printf("\n\n");
        for (
    j=0j<columns; ++j)
        {
          
    printf("%5.2Lf"matrix[i]);
        }
      }
      for (
    i=0i<rowsi++)
      {
        
    //free(matrix[i]);
      
    }
      
    free(matrix);   
      
    getch();


  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Search this forum. It doesn't work this way and workarounds have been presented.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width