C - how to convert a pointer in an array to an index?

In the many search functions of C (bsearch comes to mind) if a result is found, a pointer to the spot in the array is returned. How can I convert this pointer to the index in the array that was searched (using pointer arithmetic, i assume).

-------------Problems Reply------------

ptrdiff_t index = pointer_found - array_name;

Category:c# Views:0 Time:2010-04-26

Related post

  • Most efficient way to convert an HTMLCollection to an Array 2008-10-21

    Is there a more efficient way to convert an HTMLCollection to an Array, other than iterating through the contents of said collection and manually pushing each item into an array? --------------Solutions------------- var arr = Array.prototype.slice.ca

  • How to convert a double* to an array(6) 2009-04-14

    I have a function that returns a array of 6 doubles. double* Validation(); I would like to cast this return value in managed code. array<double>^ validationPosition = gcnew array<double>(6); validationPosition = Validation(); I get this e

  • How to convert a string to character array in c (or) how to extract a single char form string? 2009-05-15

    I need to convert a string to char array in c? How can i do this or atleast tell me how to extract a single char from string as incremental in next ??? Thanks in advance --------------Solutions------------- In C, a string is actually stored as an arr

  • AS3: How to convert a Vector to an Array 2009-07-10

    What's the nicest way to convert a Vector to an Array in Actionscript3? The normal casting syntax doesn't work: var myVector:Vector.<Foo> = new Vector(); var myArray:Array = Array(myVector); // calls the top-level function Array() due to the ex

  • F#: Converting a string into an array of bytes 2009-07-21

    I'm writing a simple rc4 encryption/decryption utility as a first project. I'm stuck on trying to convert the given string into an array of bytes that can then be manipulated by the core algorithm. How do you convert a string into an array of bytes i

  • Convert Java resultset to String array 2009-11-06

    I am writing a program that will query an MS access database, return the query as a result set, and then I want to ultimately convert that result set into a String array, so that I can pass it into the constructor of a Swing JComboBox - so the ComboB

  • How do I convert this object to an array in JavaScript? 2009-12-22

    How do I convert testObj to an array? function MinEvent(event, width, left){ this.start = event.start; this.end = event.end; this.width = width; this.top = event.start; this.left = left; } var testObj = {}; for (var j=0; j<eventLists.length; j++)

  • Convert image data to character array 2010-01-24

    I'm building a mobile advertising sdk for the iPhone and I assume that the only way to store the images that will represent the button icons for the landing page controller [in the library] is to convert the images into character arrays. When I have

  • Converting all elements of an array from string to double at once VBA 2010-02-05

    Is there a way to convert all elements of an array from string to double without having to convert each element one by one. I want to avoid to use a loop if possible. I'd like to know that for VBA not VB.Net --------------Solutions------------- In so

  • How to convert MATLAB output into an array? 2010-02-23

    I've made an M-file that outputs data into my MATLAB command window in the form below (I've deleted the extra spaces). Is there an easy way to convert this output into an array, without having to type all the data into the array editor as I'm current

  • convert a class to byte array + C# 2010-04-22

    How can I convert a Class to byte array in C#. This is a managed one so the following code is failing int objsize = System.Runtime.InteropServices.Marshal.SizeOf(objTimeSeries3D); byte[] arr = new byte[objsize]; IntPtr buff = System.Runtime.InteropSe

  • Convert comma separated string to array 2010-05-18

    I have a comma separated string that I want to convert into an array so I can loop through it. Is there anything built-in to do this? For e.g. I have this string var str = "January,February,March,April,May,June,July,August,September,October,November,

  • Most optimized/effective way to convert a collection into an array? 2010-07-06

    I know it must have been asked more than twice, but I could not find any applicable question to answer the matter. I have a collection which I wish to retrieve an array from in .NET 2.0. In other words, I want to convert a collection into an array. S

  • rails - converting an object to an array 2010-07-20

    Hey, I am trying to convert this object to an array of ints e.g. array(3,4,6) - - !ruby/object:Code attributes: candidate_id: "3" attributes_cache: {} - !ruby/object:Code attributes: candidate_id: "4" attributes_cache: {} - !ruby/object:Code attribut

  • how to convert an XML into an array in asp.net 2010-08-18

    i need to convert an XML into an array using asp.net. I tried searching on the web but couldn't find the proper solution. Can someone please help me with this Thanks, Alloi --------------Solutions------------- I find LinqToXML helpful in these circum

  • Java Convert Generic LinkedList to Generic Array 2010-09-01

    So for starters lets say that I have a LinkedList<String>, I can easily convert it to an array via toArray(). i.e. LinkedList<String> strList = new LinkedList<String>(); String[] strArray = strList.toArray(new String[0]); But Lets s

  • How to convert CSV data to paring array data using javascript? 2010-09-09

    I'm trying to convert CSV data into paring array data, but I'm totally new to javascript, and I don't know how to do it now. Does any one have some idea? Thanks in advance! CSV data: year,USA,EU,UK,China,India 2003,10882,10970,1795,1575,599 2002,1038

  • How to convert base64 string to binary array using php 2010-09-19

    I have base 64 encoded string that looks something like this. cuVrcYvlqYze3OZ8Y5tSqQY205mcquu0GsHkgXe4bPg= I have tried base64_decode and output is. råkq‹å©ŒÞÜæ|c›R©6Ó™œªë´Áäw¸lø I think I may be doing something wrong. I appreciate any help to conver

  • How can I convert an int to byte array without the 0x00 bytes? 2010-09-19

    I'm trying to convert an int value to a byte array, but I'm using the byte for MIDI information (meaning that the 0x00 byte which is returned when using GetBytes acts as a separator) which renders my MIDI information useless. I would like to convert

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.110 (s). 11 q(s)