Search Results

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

Page 126/610 | < Previous Page | 122 123 124 125 126 127 128 129 130 131 132 133  | Next Page >

  • Reading from a file into an array in c

    - by NaNa21
    My file contains a series of numbers (integer, float, integer, float ....), each written on a separate line. The numbers of columns are different from one line to another i.e. 1 2.45 3 1.75 5 3.45 7 2.55 9 3.25 6 1.75 4 3.55 6 2.55 9 2.45 The program should read the contents of the entire file and place the data into an array of type float with an entry for each line. Here is my basic solution, but this is only suitable if I have fixed no of columns. float Read(FILE *pFile) { char line[50]; char letter[5]; fi = fopen("file.txt", "r"); while (fgets(line,200,fi)!=NULL) { sscanf(line,"%f %f %f",&a[i], &a2[i],&a3[i]); printf("%2.0f %2.5f %2.0f\n",a[i],a2[i],a3[i]); } fclose(fi); return a[i]; } Please HELP.

    Read the article

  • pointers for getting elements of an array in C

    - by Manolo
    I am a newbie in C and I would like to get the elements of an array with a function, I have tried different options, but I still do not get the elements. My function is: void getelements(int *a, int cl) { int *p; for (p=&a[0];p<&a[cl];p++) { printf("%d\n",*p); } } I know that the solution should work like that, but it only prints the first element and then memory positions. I am calling my function with: int v={10,12,20,34,45}; getelements(&v,5); Any help? I need to use arithmetic of pointers. Thanks

    Read the article

  • perl Date::Manip array problem

    - by medalto
    im using Date::Manip http://search.cpan.org/~sbeck/Date-Manip-6.11/lib/Date/Manip.pod for a variety of things and want to create an array of days of the month i think I need @date = &ParseRecur("2010:4:0:0:0:0:0"); but it doesnt do it . ive read & reread the man page but cant get the syntax. @date = &ParseRecur("2010:4:0:1:0:0:0"); @date = &ParseRecur("2010:4:0:1*:0:0:0"); dont work either !

    Read the article

  • convert string array to cell in MATLAB

    - by Maddy
    I need to output a cell to an excel file. Before this I need to convert a date column of integers to datestrings. I know how to do this, but I am not able to put this new string array back into the cell - mycell = { 'AIR' [780] [1] [734472] [0.01] ; ... 'ABC' [780] [1] [734472] [0.02]} I did this -- dates = datestr(cell2mat(mycell(:,4))) ; What I need as an answer is: {'AIR' [780] [1] '14-Dec-2010' [0.01] ; 'ABC' [780] [1] '23-Dec-2010' [0.03] ; } so that I can now send it to an excel file using xlswrite.m

    Read the article

  • Problem with PHP array index.

    - by user632027
    Following code: <?php $test_array = array(); $test_array['string_index'] = "data in string index"; $test_array[] = "data in index 0"; $test_array[] = "data in index 1"; $test_array[] = "data in index 2"; foreach($test_array as $key => $val) { if($key != 'string_index') { echo $val."<br>"; } } ?> gives result: data in index 1 data in index 2 Question is - where is "data in index 0"??? How to get elements from numeric indices 0-n? Also if I change 'string_index' to something else which doesn't exist, it echoes everything except [0]. Plz, explain me this. Thnx in advance

    Read the article

  • Constructor initialising an array of subobjects?

    - by ojw
    Say I have several objects within a class, each of which needs constructing with a different value. I can write something like this: class b { public: b(int num) { // 1 for a.b1, and 2 for a.b2 } }; class a { public: b b1; b b2; a() : b1(1), b2(2) { } }; However, is it possible to do the same thing if those multiple objects are stored in an array? My first attempt at it doesn't compile: class a { public: b bb[2]; a() : bb[0](1), bb[1](2) { } };

    Read the article

  • Easy way to cast an object array into another type in C#

    - by Na7coldwater
    I want to be able to be able to quickly cast an array of objects to a different type, such as String, but the following code doesn't work: String[] a = new String[2]; a[0] = "Hello"; a[1] = "World"; ArrayList b = new ArrayList(a); String[] c = (String[]) b.ToArray(); And I don't want to have to do this: String[] a = new String[2]; a[0] = "Hello"; a[1] = "World"; ArrayList b = new ArrayList(a); Object[] temp = b.ToArray(); Object[] temp = b.ToArray(); String[] c = new String[temp.Length]; for(int i=0;i<temp.Length;i++) { c[i] = (String) temp[i]; } Is there an easy way to do this without using a temporary variable?

    Read the article

  • generating an objectForKey from an array

    - by Brian
    I'm having success when I use this code to get a string from an array of file names called "fileList": cell.timeBeganLabel.text = [[[self.fileList objectAtIndex:[indexPath row]] lastPathComponent] stringByDeletingPathExtension]; so I expected the same code to generate the same string as a key for me in this: NSDictionary *stats = [thisRecordingsStats objectForKey:[[[self.fileList objectAtIndex:[indexPath row]] lastPathComponent] stringByDeletingPathExtension]]; cell.durationLabel.text = [stats objectForKey:@"duration"]; or this: NSDictionary *stats = [thisRecordingsStats objectForKey:@"%@",[[[self.fileList objectAtIndex:[indexPath row]] lastPathComponent] stringByDeletingPathExtension]]; Both build without error, and the log shows my data is there: but I'm getting a blank UILabel. Have I not written the dynamic key generator correctly?

    Read the article

  • Removing “duplicate objects” with same attributes using Array.map

    - by keruilin
    As you can see in the current code below, I am finding the duplicate based on the attribute recordable_id. What I need to do is find the duplicate based on four matching attributes: user_id, recordable_type, hero_type, recordable_id. How must I modify the code? heroes = User.heroes for hero in heroes hero_statuses = hero.hero_statuses seen = [] hero_statuses.sort! {|a,b| a.created_at <=> b.created_at } # sort by created_at hero_statuses.each do |hero_status| if seen.map(&:recordable_id).include? hero_status.recordable_id # check if the id has been seen already hero_status.revoke else seen << hero_status # if not, add it to the seen array end end end

    Read the article

  • C# Making private instance variable accesable (jagged array)

    - by Chris
    Hello, In a attempt to put some more oop in a program i am looking to make a private instance variable in one class (object) accesable to a class. private byte [][] J; All those code refers to this jagged array with this. Now in the other class i putted all the for loops along with the consolewritlines to display the wanted results. Basicly it says "the name J does not exist in the current context" But how exactly do i make this J accesable? I have tried with get and set but i keep getting 'cannot convert to byte to byte[][]' Also what kind of cyntax would i need with get and set? Something along like this? Or would i need several more steps? : public Byte JArray get { return J; } //can converrt to byte here set { J = value; } //cannnot convert to byte here Kind regards

    Read the article

  • Get an array of forms in java script using prototype

    - by Saurabh
    My document contains more than one forms. How can I get an array of all forms using prototype? <html> <head></head> <body> <form id="form1"> <!-- Other stuffs here --> </form> <form id="form2"> <!-- Other stuffs here --> </form> <form id="form3"> <!-- Other stuffs here --> </form> </body> </html>

    Read the article

  • Error while trying to reverse a char array

    - by mpminnich
    Hi, I'm trying to get better at C++ (I know a little). I'm working on character arrays. I found an exercise where the objective is to reverse a character array (after I convert it from an integer). I'm getting the following error (using VS2005): Run-Time Check Failure #2 - Stack around the variable 'revBuffer' was corrupted. When I step through the code, I notice the following: revBuffer = 0x0012fe40 "100899ÌÌÌÌÌÌÌÌÌÌ998001" The relevant code is below. char buffer[5]; char revBuffer[5]; int i; int j=5; long number = 998001; itoa(number, buffer, 10); for(i=0; i<strlen(buffer);i++) { revBuffer[j] = buffer[i]; j--; } Any help would be great. TIA!

    Read the article

  • removing the first value in an array c# or java

    - by MrCode
    hey there i was working on a program and was thinking is it possible was to remove the value from the first element in an array. Has anyone any ideas on how this could be done ? thanks for all input is much appreciated. i have only tried removing from the last element wasnt sure on how i would remove the first this is how i done the last element try { if (isEmpty()) { throw new Exception("list is empty"); } size = size -1; return values[size]; } catch(Exception e) { System.out.println(e); return -1; }

    Read the article

  • PHP Put list from Powershell into Array

    - by Mezzan
    Code: $exchangesnapin = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010"; $output = shell_exec('powershell '.$exchangesnapin.';"get-mailboxdatabase" 2>&1'); echo( '<pre>' ); echo( $output ); echo( '</pre>' ); Result: Name Server Recovery ReplicationType ---- ------ -------- --------------- Mailbox Database 0651932265 EGCVMADTEST False None Mailbox Database 0651932266 EGCVMADTEST False None I tried with echo( $output[1] ); The result was only a letter 'N'. I believe its taking the Name column but one character at a time. $output[1] is 'N', $output[2] is 'a'. Is there any way I can get the mailbox list into array?

    Read the article

  • how to copy an array into somewhere else in the memory by using the pointer

    - by user2758510
    I am completely new in c++ programming. I want to copy the array called distances into where pointer is pointing to and then I want to print out the resul to see if it is worked or not. this is what I have done: int distances[4][6]={{1,0,0,0,1,0},{1,1,0,0,1,1},{1,0,0,0,0,0},{1,1,0,1,0,0}}; int *ptr; ptr = new int[sizeof(distances[0])]; for(int i=0; i<sizeof(distances[0]); i++){ ptr=distances[i]; ptr++; } I do not know how to print out the contents of the pointer to see how it works.

    Read the article

  • Java Int Array - Number being stored are different from ones specified

    - by Danadir
    Hey there, I have encountered the most weird problem ever in Java. When I am doing this: int []s = new int [5]; s[0] = 026; s[1] = 0011; s[2] = 1001; s[3] = 0026; s[4] = 1101; the numbers being stored in the array, seen from debug mode are different i.e. the numbers stored are 22,9,1001,22,1101. Can you give me some hints what might be wrong with this? Thanks in advance

    Read the article

  • passing array fields to jquery ajax

    - by Rob Brandt
    I have a form I am submitting via jquery ajax. Early in the form, I have this field: <select name="inquirymodule[]" id="inquirymodule"> The user can add as many as they like, and all the selects go into the inquirymodule[] array. The jQuery looks like this: jQuery.ajax({ type: 'POST', url: 'ajax.php', dataType: 'json', data: { inquirymodule: jQuery("select[name='inquirymodule[]']").serialize(), }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert('error'); } }); That works fine. Trying to do the same thing with a date, like this: <input class="formInput" type="text" id="startBreak0" name='startbreak[]' /> adding startbreak: jQuery("select[name='startbreak[]']").serialize() to the ajax call. It doesn't work, I cannot see why. Suggestions?

    Read the article

  • Problem with fetching table to array

    - by jasmine
    I have writed this function: function news_array() { $sql = "SELECT * FROM content WHERE home=1"; $query = mysql_query($sql); $i = 0; while($row = mysql_fetch_array($query)){ $row_array[$i] = array( TITLE => $row['title'], ABSTRACTT => $row['abstract'], BODY => $row['body'], ID => $row['conID'] ); $i++; } return $row_array; } When using this function like this: <?php $row_array = news_array(); for($i = 0 ; $i < count($row_array) ; $i++){ echo $row_array[$i][TITLE]; } ?> There no output in html. What is wrong in my function? Thanks in advance

    Read the article

  • Javascript function not working with an array

    - by Ryan Harvie
    Hi, i have this function which loops through an array of check boxes checking if the boxes value is equal to something in a text box, i dont know whats wrong. function checkValue(contain) { var boxes = document.getElementsByTagName("input"); for (var i = 0; i < boxes.length; i++) { if (boxes[i].name == "vote[]") { if (boxes[i].value.indexOf(contain.value) != -1) { boxes[i].checked = true; } } } } and this is how i call it OnClick="uncheckAll(); checkValue(document.getElementsByName("countrylist"));" this code is in side a echo in php which is like this echo ' ';

    Read the article

  • Troubles displaying an associative array with PHP and HTML

    - by Psyche
    Hello, I have the following HTML code: <div id="newsTicker"> <span class="icon news"></span> <ul> [repeating structure] <li> <ul> <li><a href="#">News 1</a></li> <li><a href="#">News 2</a></li> <li><a href="#">News 3</a></li> </ul> </li> [/repeating structure] </ul> </div><!--/#newsTicker--> I also have a PHP array with news (title an url) and I would like to know how can I repeat that code inside [repeating structure] and display 3 different news for each repeating structure. Thank you.

    Read the article

  • Error while trying to reverse a char array in C++

    - by mpminnich
    Hi, I'm trying to get better at C++ (I know a little). I'm working on character arrays. I found an exercise where the objective is to reverse a character array (after I convert it from an integer). I'm getting the following error (using VS2005): Run-Time Check Failure #2 - Stack around the variable 'revBuffer' was corrupted. When I step through the code, I notice the following: revBuffer = 0x0012fe40 "100899ÌÌÌÌÌÌÌÌÌÌ998001" The relevant code is below. char buffer[5]; char revBuffer[5]; int i; int j=5; long number = 998001; itoa(number, buffer, 10); for(i=0; i<strlen(buffer);i++) { revBuffer[j] = buffer[i]; j--; } Any help would be great. TIA!

    Read the article

  • Sort Array in PHP

    - by DonCroce
    I have a script which gets some values from a DB. The structure of the vars is as the following: $dump["likes"] = 1234; $likes["data"][$i]["name"] = "ABCDEFG"; for($i=0;$i<=$max;$i++){ $data[$i]["likes"] = $dump["likes"]; $data[$i]["name"] = $likes["data"][$i]["name"]; } //Print Here Sorted array (highest value in "like" first) I just need a way to find out in which entry the biggest "likes" are :) So far i have tried array_multisort, but it showed me "inconsistent size" or some error... Thanks for all your help!

    Read the article

  • How to initialize static const char array for ASCII codes [C++]

    - by Janney
    I want to initialize a static const char array with ASCII codes in a constructor, here's my code: class Card { public: Suit(void) { static const char *Suit[4] = {0x03, 0x04, 0x05, 0x06}; // here's the problem static const string *Rank[ 13 ] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'}; // and here. } However i got a whole lot of errors stating that 'initializing' : cannot convert from 'char' to 'const std::string *' 'initializing' : cannot convert from 'int' to 'const std::string *' please help me! Thank you so much.

    Read the article

  • Array to string conversion in (cant get it to work)

    - by user2966551
    ok I am trying to pull a a specific row of data that corresponds to the username logged in. on my page I have started my session but for some reason I cant get the code to work.i keep getting a "Array to string conversion in " on the line " WHERE username = '$_SESSION[user]'");" what am I doing wrong? if I set username = a set username it works but I need it to draw from the session id so it will display different values based on whos logged in. <?php $con=mysqli_connect("localhost","root","xxx","xxxx"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM users WHERE username = '$_SESSION[user]'"); while($row = mysqli_fetch_array($result)) { echo $row['username'] . " " . $row['att']; echo "<br>"; } ?>

    Read the article

< Previous Page | 122 123 124 125 126 127 128 129 130 131 132 133  | Next Page >