What are good ways to write the array_search (php function) in C and this function can use in Java(JNI)?
-
Here is the link about php function: array_search http://php.net/manual/en/function.array-search.php use the value to get the array index. I want to try write it in C language and I could use in the java program. the java program is like this: //---------------------------- //array_search java call c public class ArraySearchClient{ public native string getArrayIndex(String [] stringArray , String key) static{ System.loadLibrary(){ System.loadLibrary("ArraySearchLibrary"); } public static void main(String args []){ ArraySearchClient a = new CountIntArrayClient(); String stringList [] = { "tom","cat","jerry","mouse","lion","king"}; //Count the occurrent of the number 2 System.out.println(a.getArrayIndex(stringList, "jerry")); } } ---------------------------- ---------------------------- ---------------------------- ---------------------------- Hava some quorer could write that in different style, such as -for loop, -while loop, - (maybe could use pointer that i usually confused.. /_\ ) Also, exchange the index between 2 value of array (or you may say exchange the value between 2 index), eg : array[1] = "Tom"; array[4] = "Tommy"; after exchange, .... array[1] = "Tommy"; array[4] = "Tom"; --------------conclusion------------------- Some brother could tell me some example? programming like the php function array_search in C http://php.net/manual/en/function.array-search.php using -for loop -while loop exchange index and value using pointer (not using temp value) ------------------------the C program may like this ...... //write the C function. getArrayCount(stringList, key) #include "ArraySearchClient.h" JNIEXPORT jstring JNICALL Java_ArraySearchClient_getArrayIndex (JNIEnv *env, jobject obj, jobjectArray stringArray, jstring key){ jstring *key = null; jobject *stringArray; jboolean isCopy; const char stringArray = (*env) ->() .....??? //??????? and then ..???? } ---------------------------- ---------------------------- ---------------------------- ---------------------------- please, great Quora brother..help me..
-
Answer:
The first hurdle here is that C arrays are nothing like PHP arrays; the latter are a kind of ordered hash table. http://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-implementation.html If you literally mean a C array, then implementing a value search is a nice beginner's exercise in C.
Toby Thain at Quora Visit the source
Related Q & A:
- What are good ways to save up for an iPod Touch?Best solution by wikihow.com
- What are good ways to promote my website?Best solution by Yahoo! Answers
- What is a good printer that I can use for occasional use?Best solution by tomshardware.com
- What are good ways to get the "Last Second Bid" on eBay successfully?Best solution by ebay.com
- What are good ways for personal fund raising?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.