You still have this, which will override the passed variable:
Also, as you originally passed len - 1 to qsort(), you'll need to modify the for-loop in p_array to:
Hi all,
I am trying to create a function that return an array of integer based on the char parameter pass into the function. I.e.
func_a(char * str)
{
example str is equal to "1,2,3,4"
return an array of integers of 1,2,3,4
}
Please advise
regards
dwgi32 (2 Replies)
Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
I need to implement the following logic and need some expert help from UNIX community.
These are the steps in my Shell script.
1. Analyze a file.
2. Extract all the ID's in that file.
3. Use the ID's from #2 to run another filter on the file.
I've implemented # 1 and 2 using... (3 Replies)
Hi !
I'm looking for a way to transform certain floating point numbers in a one-line, variable length file to integers.
I can do this in a crude way with sed :
sed -e 's/0\.\(\):/\1:/g' -e 's/0\.0\(\):/\1:/g' -e 's/1\.000:/100:/g' myfile ... but this doesn't handle the rounding correctly.
... (3 Replies)
As Brendan O'Conner writes in this blog, mawk is near 8 times faster than gawk, so I am going to give mawk a go, but I got errors when trying to print the length of an array in mawk using length() function, is it not supported in mawk? or there's another way to get the length of an array in mawk?
... (3 Replies)
I would be grateful if someone could help me. I am trying to write a .sh script in UNIX.
I have the following code;
User=john
User=james
User=ian
User=martin
for x in ${User}
do
print ${#x}
done
This produces the following output;
4
5
3
6 (12 Replies)
Hello All,
I have this script that does stuff like "starting, stopping & restarting" a Daemon Process running on my machine...
My main question is why in part of my code (which you will see below) does the Array Length (i.e. ${#PIDS} )
return "1" when I know the Array is empty..?
Here is... (17 Replies)
Does anyone know how to find length of multi dimension array
of following type
A Afor simple array I is to do
for (i in A)n++ to find length of array but if it is multi dimension how to find the length ? (2 Replies)
Hi there,
I'm listing files and sorting them. When I try to get length of array variable in which these files are stored I get 1 as value. That's weird.
files_info="$(find $input_dir -name "*_CHR$i.info" | sort )"
printf ${#files_info}"\n" #print length
#--loop through... (6 Replies)
Discussion started by: genome
6 Replies
LEARN ABOUT SUNOS
qsort
qsort(3C) Standard C Library Functions qsort(3C)NAME
qsort - quick sort
SYNOPSIS
#include <stdlib.h>
void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *));
DESCRIPTION
The qsort() function is an implementation of the quick-sort algorithm. It sorts a table of data in place. The contents of the table are
sorted in ascending order according to the user-supplied comparison function.
The base argument points to the element at the base of the table. The nel argument is the number of elements in the table. The width
argument specifies the size of each element in bytes. The compar argument is the name of the comparison function, which is called with two
arguments that point to the elements being compared.
The function must return an integer less than, equal to, or greater than zero to indicate if the first argument is to be considered less
than, equal to, or greater than the second argument.
The contents of the table are sorted in ascending order according to the user supplied comparison function.
USAGE
The qsort() function safely allows concurrent access by multiple threads to disjoint data, such as overlapping subtrees or tables.
EXAMPLES
Example 1: Program sorts.
The following program sorts a simple array:
#include <stdlib.h>
#include <stdio.h>
static int
intcompare(const void *p1, const void *p2)
{
int i = *((int *)p1);
int j = *((int *)p2);
if (i > j)
return(1);
if (i < j)
return (-1);
return(0);
}
int
main()
{
int i;
int a[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
size_t nelems = sizeof (a) / sizeof (int);
qsort((void *)a, nelems, sizeof (int), intcompare);
for (i = 0; i < nelems; i++) {
(void) printf("%d ", a[i]);
}
(void) printf("
");
return(0);
}
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO sort(1), bsearch(3C), lsearch(3C), string(3C), attributes(5), standards(5)NOTES
The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being
compared.
The relative order in the output of two items that compare as equal is unpredictable.
SunOS 5.10 6 Dec 2004 qsort(3C)