HI. This is maybe simple question but I want to create two dimensional array and add it string like in java
string str = "text" ;
string [][] array = new [][] string ;
array[i][j] = str ;
But in C there is no string .I tried like this but here strcpy() gives error.It returns to assembly code. I am trying to read line by line from text and split line by space and add them to structure.But first I think that I must add each line and row in array and then making iteration and adding to structures fields.
static const char filename[] = "student.txt";
FILE *file = fopen ( filename, "r" );
char line [ 128 ]; /* or other suitable maximum line size */
char delims [ ]=" ";
char *result =NULL;
char list[15];
char arra[128][128];
int i=0;
int j=0;
struct {
char gruppa[10];
char familiya[20];
int uchaste;
struct {
int firsth;
int second;
int third;
int fourht;
int fifth;
} exam;
}student;
for(i=0; i<128; i++)
for(j=0; j<128; j++)
arra[i][j] = '\0';
for(i=0; i<15; i++)
list[i] = '\0';
if ( file != NULL )
{
while ( fgets ( line, sizeof line, file ) != NULL )
{
result = strtok(line,delims);
while (result !=NULL) {
strcpy(list,("%s",result));
strcpy(arra[i][j],list); // Here it gives errror
j++;
result = strtok(NULL,delims);
}
j=0;
i++;
}
fclose ( file );
}
else
{
perror ( filename );
}
getchar();
return 0;
}
for example i have array
int a[]=new int[]{3,4,6,2,1};
I need list of all permutation such that if one is like this, {3,2,1,4,6}, others must not be the same i know that if length of array=n then there is n! possible combination please help me to write this algortihm what to do?
In javascript is there a good(i mean built in) way that i can find whether element if array of not ? one simple i can see is as follows but i don't like it
if(ele.push){//its array it has push method}
I mean i would like know if something like below exists
function x(ele){ if(isArray(ele)){//dosomething} }
Is there significant cpu/memory overhead associated with using automatic arrays with g++/Intel on 64-bit x86 linux platform?
int function(int N) {
double array[N];
overhead compared to allocating array before hand (assuming function is called multiple times)
overhead compared to using new
overhead compared to using malloc
The range of N may be from 1kb to 16kb roughly, stack overrun is not a problem.
Hi chaps, I have an array of nsdictionaries and one key is ID (which is unique) I simply want to see if the the array of dictionaries contains a specific ID.
Really simple but its friday and after statiny up watching the election i think my brain is melting. Any help would be great.
Thanks
The CakePHP Cookbook states that a Model can use a file (csv for example) instead of an actual database table but I couldn't find any implementation for it.
I was wondering if it is possible to use an Array of data as a model in CakePHP since I have a fairly static set of data which is important to me in a relationship with another table but it doesn't make a whole lot of sense to create a complete table for it.
Is it possible to implement a CakePHP Model using an Array?
Hi,
I want to have an array of struct (an array of books with their specifications like publication, ISBN number, ...). in wsdl and php. I have searched a little and I have found files that uses Nusoap, However, I dont want to use NuSoap. Is there any solution? I would appreciate if you help me in writing the related wsdl, client and server (php) files.
Thank you so much.
Best, shadi.
All,
I have an array with hyphens in the key name. How do I extract the value of it in PHP? It returns a 0 to me, if I access like this:
print $testarray->test-key;
This is how the array looks like
testarray[] = {["test-key"]=2,["hotlink"]=1}
Thanks
I read at many tutorials that the current best practices to create a new javascript array is to use "var arr = []" instead of "var arr = new Array()".
What's the reasoning behind that?
For example, input is
Array 1 = [2, 3, 4, 5]
Array 2 = [3, 2, 5, 4]
Minimum number of swaps needed are 2.
The swaps need not be with adjacent cells, any two elements can be swapped.
I'm trying to declare an enum type based on data that I'm retrieving from a database. I have a method that returns a string array of all the rows in the table that I want to make into an enumerated type. Is there any way to construct an enum with an array?
This is what I tried, but from the way it looked in eclipse, it seemed like this just created a method by that name:
public enum ConditionCodes{
Condition.getDescriptions();
}
Thank you in advance!
Im using the answer to this question to convert an array of XML to a single XML output:
http://stackoverflow.com/questions/2554671/output-array-of-xml-to-plain-xml
Im using the simpler solution of the two there (Marked as the answer)
It all works for me, however at the start of the output I get:
string(109960) "
Can anyone shed any light on this? Output here: http://bit.ly/aoA3qY
Hello,
I have some difficulties for using Ruby block, passing in a method.
As in the following case, I would like to display each element of @array, from Box instance (using .each method):
class Box
def initialize
@array = [:foo, :bar]
end
def each(&block)
# well, hm..
end
end
a = Box.new
a.each { |element| puts element }
Thanks for any help.
Is there a way to initialize an array of primitives, say a integer array, to 0? Without using a for loop? Looking for concise code that doesn't involve a for loop.
:)
I am looking for a way to easily split a python array in half.
So that if I have an array:
A = [0,1,2,3,4,5]
I would be able to get:
B = [0,1,2]
C = [3,4,5]
somehow couldn't find this with a google search, but I feel like it has to be simple...I need to convert a string to a fixed-length byte array, e.g. write "asdf" to a byte[20] array. the data is being sent over the network to a c++ app that expects a fixed-length field, and it works fine if I use a BinaryWriter and write the characters one by one, and pad it by writing '\0' an appropriate number of times.
is there a more appropriate way to do this?
I got asked this question once and still haven't been able to figure it out:
You have an array of N integers, where N is large, say, a billion. You want to calculate the median value of this array. Assume you have m+1 machines (m workers, one master) to distribute the job to. How would you go about doing this?
Since the median is a nonlinear operator, you can't just find the median in each machine and then take the median of those values.
Let us say that we have following array:
my @arr=('Jan','Feb','Mar','Apr');
my @arr2=@arr[0..2];
How can we do the same thing if we have array reference like below:
my $arr_ref=['Jan','Feb','Mar','Apr'];
my $arr_ref2; # How can we do something similar to @arr[0..2]; using $arr_ref ?
I am trying to index a numpy.array with varying dimensions during runtime. To retrieve e.g. the first row of a n*m array a, you can simply do
a[0,:]
However, in case a happens to be a 1xn vector, this code above returns an index error:
IndexError: too many indices
As the code needs to be executed as efficiently as possible I don't want to introduce an if statement. Does anybody have a convenient solution that ideally doesn't involve changing any data structure types?
I have a object store in Java. My C program stores data (in form of char array) in java. Now I wish to retrieve data from my store. I cannot find any function call that returns me an char array. How can I do this?
Hi,
I have an array of type string that looks like this:
"test1|True,test2|False,test3|False,test4|True".
This is essentially a 2d array like so
[test1][True]
[test2][False]
[test3][False]
[test4][True].
I want to convert this into a dictionary<string,bool> using linq, something like:
Dictionary<string, bool> myResults = results.Split(",".ToCharArray).ToDictionary()
any ideas?
I have an array of field names. I would like to use those to populate the keys of another array, which will have empty values as default. Is there a single command I can do this with?
Hi all,
I came cross a question in my interview.
Question:
Array of integers will be given as the input and you should find out the middle element when sorted , but without sorting.
For Example.
Input: 1,3,5,4,2
Output: 3
When you sort the given input array, it will be 1,2,3,4,5 where middle element is 3.
You should find this in one pass without sorting.
Any solutions for this?
RubyParser.new.parse "1+1"
s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1)))
Above code is from this link
Why there is array after + in the Sexp. I am just trying to learn ruby parser and the whole AST thing. I have been programming for a while but have no formal education in computer science. So do point to good article which explains AST etc. Please no dragon book. I tried couple of times but couldn't understand much of that book