Sponsored Content
Full Discussion: alocation of 2D array
Top Forums Programming alocation of 2D array Post 302147093 by Milla on Saturday 24th of November 2007 06:52:26 PM
Old 11-24-2007
alocation of 2D array

hi I read from *.txt file size of my array and then I want to alocate this array. I have this part of code:


typedef struct tmatrix
{
int rows, cols;
int *matrix;
} TMatrix;

int readMatrix(FILE *f, TMatrix *matrix)
{
.
.
.
*matrix=alocateMatrix(rows,cols);
.
.
.
}


int alocateMatrix(r,c)
{
int **array = malloc(r*sizeof(int *));
for (j = 0; j < matice->r; j++)
array[j] = malloc(c*sizeof(int));
return // what would this funcion return? I tried something, but wasnot OK
}



//then I dealocated:
void freeMatrix(TMatrix *matrix)
{
int i;
for (i=0;i<matrix->rows;i++) free(matrix->matrix[i]);
free(matrix->matrix);
free(matrix);
}


If you give some ideas or some other help, I will be lucky
Thanks a lot
Milla
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies

2. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

3. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

4. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

5. Shell Programming and Scripting

Store all the passed arguments in an array and display the array

Hi I want to write a script which store all the parameters passed to the script into an array. Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD. I want to know how can I... (3 Replies)
Discussion started by: dgmm
3 Replies

6. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

9. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

10. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies
libpgm(3)						     Library Functions Manual							 libpgm(3)

NAME
libpgm - functions to support portable graymap (PGM) programs SYNOPSIS
#include <pgm.h> void pgm_init( int *argcP, char *argv[] ); gray ** pgm_allocarray( int cols, int rows ); gray * pgm_allocrow( intcols ); void pgm_freearray( gray **grays, introws ); void pgm_freerow( gray *grayrow); void pgm_readpgminit( FILE *fp, int *colsP, int *rowsP, gray *maxvalP, int *formatP ); void pgm_readpgmrow( FILE *fp, gray *grayrow, int cols, gray maxval, int format ); gray ** pgm_readpgm( FILE *fp, int *colsP, int *rowsP, gray *maxvalP ); void pgm_writepgminit( FILE * fp , int cols, int rows, gray maxval, int forceplain ); void pgm_writepgmrow( FILE *fp, gray *grayrow, int cols, gray maxval, int forceplain ); void pgm_writepgm( FILE *fp, gray ** grays, int cols, int rows, gray maxval, int forceplain ); void pgm_writepgm( FILE *fp, gray **grays, int cols, int rows, gray maxval, int forceplain ); void pgm_nextimage( FILE *file, int * const eofP); void pgm_check( FILE * file, const enum pm_check_type check_type, const int format, const int cols, const int rows, const int maxval, enum pm_check_code * const retval); typedef ... gray; #define PGM_MAXMAXVAL ... #define PGM_OVERALLMAXVAL ... extern gray pgm_pbmmaxval; #define PGM_FORMAT ... #define RPGM_FORMAT ... #define PGM_TYPE PGM_FORMAT #define PGM_FORMAT_TYPE(format) ... DESCRIPTION
TYPES AND CONSTANTS Each gray should contain only the values between 0 and PGM_OVERALLMAXVAL. pgm_pbmmaxval is the maxval used when a PGM program reads a PBM file. Normally it is 1; however, for some programs, a larger value gives better results. PGM_OVERALLMAXVAL is the maximum value of a maxval in a PGM file. PGM_MAXMAXVAL is the maximum value of a maxval in a PGM file that is compatible with the PGM format as it existed before April 2000. It is also the maximum value of a maxval that results in the minimum pos- sible raster size for a particular image. I.e an image with a maxval higher than PGM_MAXMAXVAL cannot be read or generated by old PGM pro- cessing programs and requires more file space. PGM_FORMAT is the format code for a Plain PGM format image file. RPGM_FORMAT is the format code for a Raw PGM format image file. PGM_TYPE is the format type code for the PGM formats. PGM_FORMAT_TYPE is a macro that generates code to compute the format type code of a PBM or PGM format from the format code which is its argument. INITIALIZATION All PGM programs must call pgm_init() just after invocation, before they process their arguments. MEMORY MANAGEMENT pgm_allocarray() allocates an array of grays. pgm_allocrow() allocates a row of the given number of grays. pgm_freearray() frees the array allocated with pgm_allocarray() containing the given number of rows. pgm_freerow() frees a row of grays allocated with pgm_allocrow(). READING FILES If a function in this section is called on a PBM format file, it translates the PBM file into a PGM file on the fly and functions as if it were called on the equivalent PGM file. The format value returned by pgm_readpgminit() is, however, not translated. It represents the actual format of the PBM file. pgm_readpgminit() reads the header of a PGM file, returning all the information from the header and leaving the file positioned just after the header. pgm_readpgmrow() reads a row of grays into the grayrow array. format, cols, and maxval are the values returned by pgm_readpgminit(). pgm_readpgm() reads an entire PGM image into memory, returning the allocated array as its return value and returning the information from the header as rows, cols, and maxval. This function combines pgm_readpgminit(), pgm_allocarray(), and pgm_readpgmrow(). WRITING FILES pgm_writepgminit() writes the header for a PGM file and leaves it positioned just after the header. forceplain is a logical value that tells pgm_writepgminit() to write a header for a plain PGM format file, as opposed to a raw PGM format file. pgm_writepgmrow() writes the row grayrow to a PGM file. For meaningful results, cols, maxval, and forceplain must be the same as was used with pgm_writepgminit(). pgm_writepgm() write the header and all data for a PGM image. This function combines pgm_writepgminit() and pgm_writepgmrow(). MISCELLANEOUS pgm_nextimage() positions a PGM input file to the next image in it (so that a subsequent pgm_readpgminit() reads its header). pgm_nextimage() is analogous to pbm_nextimage(), but works on PGM and PBM files. pgm_check() checks for the common file integrity error where the file is the wrong size to contain all the image data. pgm_check() is analogous to pbm_check(), but works on PGM and PBM files. SEE ALSO
libpbm(3), libppm(3), libpnm(3) libpgm(3)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy