Hi,
I have the following problem: i must allocate a dynamic array from a subroutine which should return such array to main function. The subroutine has already a return parameter so i thought of pass the array as I/O parameter. I tried the following program but it doesn't work (segmentation fault), i think because i should have a pointer to array, but i'm not sure.
Last edited by littleboyblu; 03-26-2009 at 10:33 AM..
Hi,
Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me
New to scripting
Gundu (3 Replies)
Could one of you, please, provide some input regarding my problem below and it is as follows:
I have 2 files that I need to make sure are identical before processing:
First, I sort both files
Second, I do a diff file1 file2 > File 3
This provides me with the difference.
Now, I need to... (6 Replies)
i want to create an array
the array elements are populated depending upon the number of entries present in a data file
The data file is created dynamically
how to achieve the same
thanks (1 Reply)
Hi,
I am trying to process line by line of a file. But I should not be allocating static allocation for reading the contents of the file. The memory should be dynamically allocated. The confusion here is how do I determine the size of each line, put it into a buffer with the memory allocated... (11 Replies)
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)
i wrote a tiny version of tail command using a large buffer statically allocated but, in a second time, i found another version in which i use a bidimensional array dynamically allocated.
here is the first version
/*my tiny tail, it prints the last 5 line of a file
*/
#include<stdio.h>... (4 Replies)
Hi,
I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Hello,
Can somebody please give me a snippet for the below requirement.
I want to assign the values separeted by a comma to be assigned to a dynamic array.
If I give an input (read statement) like abc1,abc2,abc3,abc4,abc5, all these strings abc* should be assigned to an array like below... (2 Replies)
Hello Guys
I have a small confusion in the dynamic memory allocation concept.
If we declare a pointer say a char pointer, we need to allocate adequate memory space.
char* str = (char*)malloc(20*sizeof(char));
str = "This is a string";
But this will also work.
char* str = "This... (2 Replies)
Discussion started by: tene
2 Replies
LEARN ABOUT FREEBSD
scandir
SCANDIR(3) BSD Library Functions Manual SCANDIR(3)NAME
scandir, alphasort -- scan a directory
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <dirent.h>
int
scandir(const char *dirname, struct dirent ***namelist, int (*select)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
int
scandir_b(const char *dirname, struct dirent ***namelist, int (*select(rp(const struct dirent *),
int (^compar)(const struct dirent **, const struct dirent **));
int
alphasort(const struct dirent **d1, const struct dirent **d2);
DESCRIPTION
The scandir() function reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the num-
ber of entries in the array. A pointer to the array of directory entries is stored in the location referenced by namelist.
The select argument is a pointer to a user supplied subroutine which is called by scandir() to select which entries are to be included in the
array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be
included in the array. If select is null, then all the directory entries will be included.
The compar argument is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is
null, the array is not sorted.
The alphasort() function is a routine which can be used for the compar argument to sort the array alphabetically using strcoll(3).
The memory allocated for the array can be deallocated with free(3), by freeing each pointer in the array and then the array itself.
The scandir_b() function behaves in the same way as scandir(), but takes blocks as arguments instead of function pointers and calls qsort_b()
rather than qsort().
DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures.
SEE ALSO directory(3), malloc(3), qsort(3), strcoll(3), dir(5)HISTORY
The scandir() and alphasort() functions appeared in 4.2BSD.
BSD January 3, 2010 BSD