Search Results

Search found 15239 results on 610 pages for 'array population'.

Page 123/610 | < Previous Page | 119 120 121 122 123 124 125 126 127 128 129 130  | Next Page >

  • Finding unique elements in an string array in C

    - by LuckySlevin
    Hi, C bothers me with its handling of strings. I have a pseudocode like this in my mind: char *data[20]; char *tmp; int i,j; for(i=0;i<20;i++) { tmp = data[i]; for(j=1;j<20;j++) { if(strcmp(tmp,data[j]))//then except the uniqueness, store them in elsewhere. } } But when i coded this the results were bad.(I handled all the memory stuff,little things etc.) The problem is in the second loop obviously :D. But i cannot think any solution. How do i find unique strings in an array. Example input : abc def abe abc def deg entered unique ones : abc def abe deg should be found.

    Read the article

  • how to modify a json array with jQuery

    - by Emin
    I have the following json array of objects in my code var groups = [ { "gid": 28, "name": "Group 1", "ishidden": false, "isprivate": false }, { "gid": 16, "name": "Group 2", "ishidden": true, "isprivate": false }, { "gid": 31, "name": "Group 3", "ishidden": true, "isprivate": false }, { "gid": 11, "name": "Group 4", "ishidden": false, "isprivate": false }, { "gid": 23, "name": "Group 5", "ishidden": false, "isprivate": false } ]; I can access or iterate through this with no problm using jQuery. However a situation arose where I need to change a value of one of the items (e.g. change the ishidden property to true for gid: 28) and then run some other jQuery function against it. Is this possible? or do I have to re-build the whole object ? If possible, how can I achieve this? any help would be appreciated!

    Read the article

  • Deserialize array values to .NET properties using DataContractJsonSerializer

    - by James Cadd
    I'm working with the DataContractJsonSerializer in Silverlight 4 and would like to deserialize the following JSON: { "collectionname":"Books", "collectionitems": [ ["12345-67890",201, "Book One"], ["09876-54321",45, "Book Two"] ] } Into classes like the following: class BookCollection { public string collectionname { get; set; } public List<Book> collectionitems { get; set; } } class Book { public string Id { get; set; } public int NumberOfPages { get; set; } public string Title { get; set; } } What's the proper place to extend DataContractJsonSerializer to map the unnamed first array element in "collectionitems" to the Id property of the Book class, the second element to the NumberOfPages property and the final element to Title? I don't have control over the JSON generation in this instance and would like the solution to work with the Silverlight subset of .NET. It would be great if the solution could perform the reverse for serialization as well.

    Read the article

  • Custom accessor for array element

    - by memph1s
    I'm trying to create an accessor for one element from array with specific flag set to true: class EntranceObject < ActiveRecord::Base has_many :subscribers def customer self.subscribers.find(:first, :conditions => {:is_customer => true}) end def customer=(customer_params) self.subscribers << Subscriber.new(:name => customer_params[:name], :apartment => customer_params[:apartment], :phone_number => customer_params[:phone_number], :is_customer => true) end end class Subscriber < ActiveRecord::Base belongs_to :entrance_object validates_presence_of :name, :apartment end How do i need to validate this accessor in order to hightlight missing fields in a view? P.S. I'm newbie in RoR, maybe there is another approach to such work with one element from a collection? Thanks.

    Read the article

  • Rails - JSON object with an array?

    - by AnApprentice
    Hello, I'm able to create and send a JSON object like so: @mylist << { :id => item.id, :name => name.id } render :json => { :result => 'success', :mylist => @mylist } That works great. Problem I'm having now is that I need to include users with are 1 or more per item. @mylist << { :id => item.id, :name => name.id, :users => item.users } Where item.users contains a list of (user.id, user.name, user.desc). how do I include an array like users inside a json object? How to build in Rails and then how to parse it with jQuery? Thanks

    Read the article

  • Simpler array declaration syntax in c++

    - by AareP
    In the spirit of Go-language, where simpler syntax is considered pretty important, here's a proposal for simpler array declaration in c++: int value; int_1 list; int_2 table; int_3 cube; RECT rect; RECT_1 rects; Using typedefs this can expand to: int value; vector<int> list; vector<int> table; vector<int> cube; RECT rect; vector<RECT> rects; Would you use it, or is there such a thing as too simple syntax?

    Read the article

  • Twitter Trends API weekly.json causing error "Cannot use object of type stdClass as array"

    - by tucson
    I have the following PHP code: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch); $obj = json_decode($result); foreach ($obj[0]->trends as $trend) echo utf8_decode($trend->name); which works fine for URL #1 (into the variable $URL): http://api.twitter.com/1/trends/1.json?exclude=hashtags but causes an error "Cannot use object of type stdClass as array" for URL #2: http://api.twitter.com/1/trends/weekly.json?exclude=hashtags I have searched for a while, but can't figure out a code to fix this and handle both URLs. Any help would be much appreciated.

    Read the article

  • Building and rendering a bitmap from a double array

    - by Ami
    I'm new to c# and I'm sure I'm missing something simple here. I'm trying to build a bitmap from integer values (0-255) in a double array and then render it in a PictureBox. I think my Bitmap is getting generated but it isn't displaying in my PictureBox. Bitmap bmp = new Bitmap(image_width, image_height); Color pxl_color = new Color(); for (int i = 0; i < image_width; i++) { for (int j = 0; j < image_height; j++) { pxl_color = Color.FromArgb(array_bitmap[i][j]); bmp.SetPixel(i, j, pxl_color); } } PictureBox1.Image = bmp; Thanks in advance.

    Read the article

  • Sorting array of structs

    - by mrblippy
    Hi, i am having trouble making a method to sort an array of structs. i am tring to sort them in ascending order based on classcode. any help you could give would be appreciated struct unit { char classcode[4]; char *classname; }; void insertion_sort(struct unit u[], int n) { int j, p; struct unit tmp[1]; for(p = 1; p < n; p++) { tmp[0] = u[p]; for(j = p; j > 0 && (strcmp(tmp[j-1].classcode, tmp[p].classcode) > 0); j--) u[j] = u[j-1]; u[j] = tmp[0]; } }

    Read the article

  • A RAM error of big array

    - by flint
    I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code: _L1 = [[0 for col in range(13496)] for row in range(13496)] _L1file = open('distanceCMD.function.txt') while (i<13496): print "i="+str(i) _strlf = _L1file.readline() _strlf = _strlf.split('\t') _strlf = _strlf[:-1] _L1[i] = _strlf i += 1 _L1file.close() And this is my error massage: MemoryError: File "D:\research\space-function\ART3.py", line 30, in <module> _strlf = _strlf.split('\t')

    Read the article

  • Deleting an element from an array in perl

    - by Flamewires
    Hey I'm wondering how i can get this code to work, basically i want to keep the lines of $filename as long as they contain the $user in the path. Sry, perl noob. open STDERR, ">/dev/null"; $filename=`find -H /home | grep $file`; @filenames = split(/\n/, $filename); for $i (@filenames) { if ($i =~ m/$user/) { #keep results } else { delete $i; # does not work. } } $filename = join ("\n", @filenames); close STDERR; I know you can delete like delete $array[index] but I don't have an index with this kind of loop that I know of.

    Read the article

  • is there a native php function to see if one array of values is in another array?

    - by Haroldo
    Is there a better method than loop with strpos()? Not i'm looking for partial matches and not an in_array() type method. example needle and haystack and desired return: $needles[0] = 'naan bread'; $needles[1] = 'cheesestrings'; $needles[2] = 'risotto'; $needles[3] = 'cake'; $haystack[0] = 'bread'; $haystack[1] = 'wine'; $haystack[2] = 'soup'; $haystack[3] = 'cheese'; //desired output - but what's the best method of getting this array? $matches[0] = 'bread'; $matches[1] = 'cheese';

    Read the article

  • Organize array in PHP from mysql

    - by Matthew Carter
    Hi i have a social networking website. what i want it to do is pull out my friends status updates. basically what it does is i have a mysql query that pulls out all of my friends and in that while loop there is another mysql query that pulls out the status's from my friends. i want it to be in order of date but since its one while loop in another what it does is pull out all status's from friend 1 then 2 then 3 and not in order by date. i even tried ORDER BY DATE but that just ordered it by date within the friend.. my thought is that i could putt it all in an array and friends is one thing and the values is the stats. then just sort by values would this work and how could i do it. THANKS SO MUCH

    Read the article

  • PHP Type Hinting: array supported, object NOT?

    - by Marius Burz
    Am I missing something or there really is no support for generic object type hinting in PHP 5.x? I find it really strange that hinting arrays is supported while hinting objects is not, at least not out of the box. I'd like to have something like this: function foo(object $o) Just as we have: function foo(array $o) Example of possible use: methods of an objects collection class. Workaround: using an interface "Object" implemented by all classes or extending all classes from a generic class "Object" and writing something like this: function foo(Object $o) Well, that just ain't cute. Edit: somebody suggested in a deleted post using stdClass. It doesn't work: Catchable fatal error: Argument 1 passed to c::add() must be an instance of stdClass, instance of b given

    Read the article

  • When should an array name be treated as a pointer and when does it just represent the array itself? [duplicate]

    - by user1087373
    This question already has an answer here: When is an array name or a function name 'converted' into a pointer ? (in C) 4 answers I just made a test program after reading the book and the result turned out confusing: #include <stdio.h> int main(void) { char text[] = "hello!"; printf("sizeof(text):%d sizeof(text+2):%d sizeof(text[0]):%d \n",(int)sizeof(text), sizeof(text+2), sizeof(text[0])); printf("text:%p sizeof(text):%d &text:%p sizeof(&text):%d \n",text, sizeof(text), &text, sizeof(&text)); printf("text+1:%p &text+1:%p \n", text+1, &text+1); return 0; } The result: sizeof(text):7 sizeof(text+2):4 sizeof(text[0]):1 text:0xbfc8769d sizeof(text):7 &text:0xbfc8769d sizeof(&text):4 text+1:0xbfc8769e &text+1:0xbfc876a4 What makes me feel confused are: why the value of 'sizeof(text)' is 7 whereas 'sizeof(text+2)' is 4 what's the difference between 'text' and '&text'?

    Read the article

  • Array index is not accessable because it is Friend

    - by user3738194
    I am getting and error when I bring my code into another project. In a blank project it works fine, I really have no idea how to get around it, here is the error Error 1 'System.Data.Index' is not accessible in this context because it is 'Friend'. Dim DataString As String = txtAdvancedCommand.Text ' Create an array containing from each letter in Textbox Dim charArray() As Char = DataString.ToCharArray For index = 0 To charArray.GetUpperBound(0) <-----ERROR on word index Try 'Now lets send the data If SerialPort.IsOpen Then SerialPort.Write(charArray(index) & vbCrLf) <-----ERROR on word index Else ConnectSerial() SerialPort.Write(charArray(index) & vbCrLf) <-----ERROR on word index End If Catch e As Exception txtLog.AppendText(e.Message & vbCrLf) End Try Next now the project I am bringing into has a DLL and I suspect it has something to do with it, I cannot get the source code to the DLL so is there another way around this?

    Read the article

  • casting a generic array in java

    - by liloboy
    The implementation is for a linked list in java : public AnyType[] toArr() { AnyType[] arr = (AnyType[]) new Object[size]; int i = 0; Node<AnyType> current = head.next; while (cur != head){ arr[i] = current.data;// fill the array i++; current = current.next; } return arr; } public static void main(String[] args) { System.out.println(ll.toArr().toString()); } The error that I get: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer; Thanks.

    Read the article

  • UIPickerView and empty core data array

    - by Mark
    I have a viewcontroller showing items from a core data entity. I also have a tableview listing records from the same entity. The table is editable, and the user could remove all the records. When this happens, the view controller holding the pickerview bombs because it's looking for records in an empty array. How to prevent this? I'm assuming I need to do something different at objectAtIndex:row... # pragma mark PickerView Section - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; // returns the number of columns to display. } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [profiles count]; // returns the number of rows } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { // Display the profiles we've fetched on the picker Profiles *prof = [profiles objectAtIndex:row]; return prof.profilename; } //If the user chooses from the pickerview - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { selectedProfile = [[profiles objectAtIndex:row]valueForKey:@"profilename"]; }

    Read the article

  • Getting the class of an n dimensional array of an runtime supplied class name

    - by MeBigFatGuy
    Given a fully qualified class name, and a number of dimensions, i would like to get the Class name for this class. I believe i can do this like such public Class<?> getArrayClass(String className, int dimensions) throws ClassNotFoundException { Class<?> elementType = Class.forName(className); return Array.newInstance(elementType, new int[dimensions]).getClass(); } However this requires me to create an unneeded instance of the class. Is there a way to do this without creating the instance? It does not appear that Class.forName("[[[[Ljava/lang/String;") (or a algorithmically generated version) works correctly in all instances from various blog posts i've seen.

    Read the article

  • Sqlite database entries pass to array list?

    - by Rjay Guillermo Baltazar
    This is my code in getting the question into SQLite Database . I want to pass the questions into array list ? is it possible to my code ? Thanks for your help . public String getquestions() { // TODO Auto-generated method stub String[] sqlSelect = { "0 _id", "question", "answer" }; String sqlTables = "mytables"; SQLiteDatabase db = getWritableDatabase(); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(sqlTables); String result = ""; c = qb.query(db, sqlSelect, null, null, null, null, null); int id = c.getColumnIndex(ID); int question = c.getColumnIndex(ROW1); int answer = c.getColumnIndex(ROW2); c.moveToFirst(); result = result + c.getString(question) + c.getString(count); return result; }

    Read the article

  • Create a class with array of objects.

    - by Bi
    Hi Code below defines a ChargeCustomer class that contains an array of type "customers". I want to be able to create an object with either 1 "customer" or 2 "customers" based on the constructor parameters. Is this the right way to do so in C#: public class ChargeCustomer { private Customer[] customers; public ChargeCustomer( string aName, string bName, int charge ) { customers = new Customer[2]; customers[0] = new Customer(aName, charge); customers[1] = new DropBox(bName, charge); } public ChargeCustomer( string bName, int charge ) { customers = new Customer[1]; customers[0] = new Customer( bName, charge ); } } Thanks!

    Read the article

  • Getting plane slices from array data

    - by umanga
    Greetings all, I read 3d grid data (from multiple TIF images) into a structure as follows : typedef struct VolumeData{ int nx; int ny; int nz; unsigned char *data; // size is nx*ny*nz } Now I want to get the plane slices from this 1-D grid data: eg: unsigned char* getXYPlaneStack(VolumeData *vol,int z); I could implement above function because the *data array stores image stack. But i am having difficult time implement along the other axes: unsigned char* getYZPlaneStack(VolumeData *vol,int x); and unsigned char* getXZPlaneStack(VolumeData *vol,int y); any easy algorithm for this? thanks in advance.

    Read the article

  • C++ vector of char array

    - by Stuart
    I am trying to write a program that has a vector of char arrays and am have some problems. char test [] = { 'a', 'b', 'c', 'd', 'e' }; vector<char[]> v; v.push_back(test); Sorry this has to be a char array because I need to be able to generate lists of chars as I am trying to get an output something like. a a a b a c a d a e b a b c Can anyone point me in the right direction? Thanks

    Read the article

  • Building 16 bit os - character array not working

    - by brainbarshan
    Hi. I am building a 16 bit operating system. But character array does not seem to work. Here is my example kernel code: asm(".code16gcc\n"); void putchar(char); int main() { char *str = "hello"; putchar('A'); if(str[0]== 'h') putchar('h'); return 0; } void putchar(char val) { asm("movb %0, %%al\n" "movb $0x0E, %%ah\n" "int $0x10\n" : :"m"(val) ) ; } It prints: A that means putchar function is working properly but if(str[0]== 'h') putchar('h'); is not working. I am compiling it by: gcc -fno-toplevel-reorder -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0 What should I do?

    Read the article

  • SQL returns non-array value in PHP

    - by DeadMG
    $request = 'SELECT * FROM flight WHERE Id = \''.$_SESSION['LFLightRadio'].'\''; $data = mysql_fetch_array(mysql_query($request, $SQL)); echo '<table class="table">'; foreach($data as $key => $value) { echo '<th class="head" align="center" height="19">'.$key.'</th>'; } echo '<tr>'; foreach($data as $key => $value) { echo '<td class="cell" align="center" height="19">'.$value.'</td>'; } echo '</tr></table>'; I know that the LFlightRadio value is set, and is a value returned by the Id value of a previously returned row from the flight database. So within "flight", a record definitely exists with this Id. But, this still gives me a non-array result, so that when I try to use foreach on it, it errors out. Suggestions?

    Read the article

< Previous Page | 119 120 121 122 123 124 125 126 127 128 129 130  | Next Page >