Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help: stdin to multi-dimensional array Post 302507447 by unt_engn on Wednesday 23rd of March 2011 10:54:24 PM
Old 03-23-2011
Help: stdin to multi-dimensional array

I cant get out of this while loop at the beginning of my program. Just reading from stdin one char at a time and storing it into a multi-array. Need to fix it with in two hours.
Code:
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char* argv[]){
char character;
char temp;
int i = 0;
int c = 0;
int j = 1;
int y = 0;
char line[20][20];
int count=0;

printf("Please enter your exec file and its arguments and pres ENTER.\n");        

do{
    temp = getchar();
            
        if(temp == ' '){
            line[count][i] = '\0';
            i = 0;    
            count++;
      }
            else{
                 line[count][i] = temp;    
                 i++;
                        
            }    
                          printf("%c", line[count][i-1]);            
    }while(temp != '\0');

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can there be multi-dimensional variable arrays in borne shell?

Hello - I've serached the web but can't find much on array script variables (except that C-shell variables are arrays!) I'm trying to form a 2-D string array: (this is what I want, but in java) String list = { {"one", "two"}, {"three"} }; I know this is a 1-D string array shell... (4 Replies)
Discussion started by: jparker
4 Replies

2. Programming

Multi-Dimensional Arrays

So, I'm fooling around with multi demtional arrays, and I made this in a short amount of time: #include <stdio.h> main(int argc, char *argv) { char blah = { {'a', 'b'}, {'b', 'a'} }; int i = 0; while (i < 2) { if (argv == blah) printf("%c\n", blah); i++; } } The goal... (3 Replies)
Discussion started by: Octal
3 Replies

3. Shell Programming and Scripting

Multi Dimensional array in KSH

Is there any way to use multi dim. array in KSH ? (1 Reply)
Discussion started by: sinpeak
1 Replies

4. Shell Programming and Scripting

Manipulating Pick multi dimensional data with awk.

Hi. I am reasonably new to awk, but have done quite a lot of unix scripting in the past. I have resolved the issues below with unix scripting but it runs like a dog. Moved to awk for speed and functionality but running up a big learning curve in a hurry, so hope there is some help here. I... (6 Replies)
Discussion started by: mike.strategis
6 Replies

5. Shell Programming and Scripting

PHP: how can I delete empty/NULL elements from a multi-dimensional array.

Hi all I have a file that i'm running and exec(cat ./dat) against..and putting its contents into any array, then doing an exploding the array into a multi-dimension array... The 15 multi-dimensional arrays have elements that are null/empty, I would like to remove/unset these elements and then... (2 Replies)
Discussion started by: zeekblack
2 Replies

6. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

7. Shell Programming and Scripting

Match elements in an AWK multi-dimensional array

Hello, I have two files in the following format; file1: A B C D E F G H I J K L file2: 1 2 3 4 5 6 7 8 9 10 11 12 I have read them both in to multi-dimensional arrays. I need a file that has column 2 of the first file printed out for each column 3 of the second file ie... ... (3 Replies)
Discussion started by: cold_Que
3 Replies

8. Shell Programming and Scripting

sorting multi dimensional array

Hi there, Can someone let me know how to sort the 2 dimensional array below by column 1 then by column 2? 22 55 2222 2230 33 66 44 58 222 240 11 25 22 60 33 45 output: 11 25 22 55 22 60 33 45 33 66 44 58 (6 Replies)
Discussion started by: phoeberunner
6 Replies

9. Shell Programming and Scripting

Multi Dimensional array

I have an array of names. Each one of the name, has a number represented to it. For example A has an ID 8, B has an ID 2. What I am after is a for loop that when the array is in position 1, a particular variable is set to the value of position 1 in array 2 declare -a arr=("A" "B" "C"... (6 Replies)
Discussion started by: nms
6 Replies

10. Shell Programming and Scripting

Multi Dimensional array in bash

Hi, I'm developing a script which contains a multi dimensional array, however for some reason the array is not iterating. When executing the script, services are listed as arguments from argument 2. Ex voice data sms. service=${@:2}; for services in $service do ... (2 Replies)
Discussion started by: nms
2 Replies
Bigarray(3)							   OCaml library						       Bigarray(3)

NAME
Bigarray - Large, multi-dimensional, numerical arrays. Module Module Bigarray Documentation Module Bigarray : sig end Large, multi-dimensional, numerical arrays. This module implements multi-dimensional arrays of integers and floating-point numbers, thereafter referred to as ``big arrays''. The implementation allows efficient sharing of large numerical arrays between OCaml code and C or Fortran numerical libraries. Concerning the naming conventions, users of this module are encouraged to do open Bigarray in their source, then refer to array types and operations via short dot notation, e.g. Array1.t or Array2.sub . Big arrays support all the OCaml ad-hoc polymorphic operations: -comparisons ( = , <> , <= , etc, as well as Pervasives.compare ); -hashing (module Hash ); -and structured input-output (the functions from the Marshal module, as well as Pervasives.output_value and Pervasives.input_value ). === Element kinds === === Big arrays can contain elements of the following kinds: - IEEE single precision (32 bits) floating-point numbers (Bigar- ray.float32_elt), - IEEE double precision (64 bits) floating-point numbers (Bigarray.float64_elt), - IEEE single precision (2 * 32 bits) floating-point complex numbers (Bigarray.complex32_elt), - IEEE double precision (2 * 64 bits) floating-point complex numbers (Bigar- ray.complex64_elt), - 8-bit integers (signed or unsigned) (Bigarray.int8_signed_elt or Bigarray.int8_unsigned_elt), - 16-bit integers (signed or unsigned) (Bigarray.int16_signed_elt or Bigarray.int16_unsigned_elt), - OCaml integers (signed, 31 bits on 32-bit architectures, 63 bits on 64-bit architectures) (Bigarray.int_elt), - 32-bit signed integer (Bigarray.int32_elt), - 64-bit signed integers (Bigar- ray.int64_elt), - platform-native signed integers (32 bits on 32-bit architectures, 64 bits on 64-bit architectures) (Bigar- ray.nativeint_elt). Each element kind is represented at the type level by one of the abstract types defined below. === type float32_elt type float64_elt type complex32_elt type complex64_elt type int8_signed_elt type int8_unsigned_elt type int16_signed_elt type int16_unsigned_elt type int_elt type int32_elt type int64_elt type nativeint_elt type ('a, 'b) kind To each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the big array or read back from it. This type is not necessarily the same as the type of the array elements proper: for instance, a big array whose elements are of kind float32_elt contains 32-bit single precision floats, but reading or writing one of its elements from OCaml uses the OCaml type float , which is 64-bit double precision floats. The abstract type ('a, 'b) kind captures this association of an OCaml type 'a for values read or written in the big array, and of an ele- ment kind 'b which represents the actual contents of the big array. The following predefined values of type kind list all possible associ- ations of OCaml types with element kinds: val float32 : (float, float32_elt) kind See Bigarray.char . val float64 : (float, float64_elt) kind See Bigarray.char . val complex32 : (Complex.t, complex32_elt) kind See Bigarray.char . val complex64 : (Complex.t, complex64_elt) kind See Bigarray.char . val int8_signed : (int, int8_signed_elt) kind See Bigarray.char . val int8_unsigned : (int, int8_unsigned_elt) kind See Bigarray.char . val int16_signed : (int, int16_signed_elt) kind See Bigarray.char . val int16_unsigned : (int, int16_unsigned_elt) kind See Bigarray.char . val int : (int, int_elt) kind See Bigarray.char . val int32 : (int32, int32_elt) kind See Bigarray.char . val int64 : (int64, int64_elt) kind See Bigarray.char . val nativeint : (nativeint, nativeint_elt) kind See Bigarray.char . val char : (char, int8_unsigned_elt) kind As shown by the types of the values above, big arrays of kind float32_elt and float64_elt are accessed using the OCaml type float . Big arrays of complex kinds complex32_elt , complex64_elt are accessed with the OCaml type Complex.t . Big arrays of integer kinds are accessed using the smallest OCaml integer type large enough to represent the array elements: int for 8- and 16-bit integer bigarrays, as well as OCaml-integer bigarrays; int32 for 32-bit integer bigarrays; int64 for 64-bit integer bigarrays; and nativeint for platform-native integer bigarrays. Finally, big arrays of kind int8_unsigned_elt can also be accessed as arrays of characters instead of arrays of small integers, by using the kind value char instead of int8_unsigned . === Array layouts === type c_layout See Bigarray.fortran_layout . type fortran_layout To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for big arrays, one compatible with the C conventions, the other compatible with the Fortran conventions. In the C-style layout, array indices start at 0, and multi-dimensional arrays are laid out in row-major format. That is, for a two-dimen- sional array, all elements of row 0 are contiguous in memory, followed by all elements of row 1, etc. In other terms, the array elements at (x,y) and (x, y+1) are adjacent in memory. In the Fortran-style layout, array indices start at 1, and multi-dimensional arrays are laid out in column-major format. That is, for a two-dimensional array, all elements of column 0 are contiguous in memory, followed by all elements of column 1, etc. In other terms, the array elements at (x,y) and (x+1, y) are adjacent in memory. Each layout style is identified at the type level by the abstract types Bigarray.c_layout and fortran_layout respectively. type 'a layout The type 'a layout represents one of the two supported memory layouts: C-style if 'a is Bigarray.c_layout , Fortran-style if 'a is Bigar- ray.fortran_layout . === Supported layouts The abstract values c_layout and fortran_layout represent the two supported layouts at the level of values. === val c_layout : c_layout layout val fortran_layout : fortran_layout layout === Generic arrays (of arbitrarily many dimensions) === module Genarray : sig end === One-dimensional arrays === module Array1 : sig end One-dimensional arrays. The Array1 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of one-dimensional arrays. (The Array2 and Array3 structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking. === Two-dimensional arrays === module Array2 : sig end Two-dimensional arrays. The Array2 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of two-dimensional arrays. === Three-dimensional arrays === module Array3 : sig end Three-dimensional arrays. The Array3 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of three-dimensional arrays. === Coercions between generic big arrays and fixed-dimension big arrays === val genarray_of_array1 : ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given one-dimensional big array. val genarray_of_array2 : ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given two-dimensional big array. val genarray_of_array3 : ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given three-dimensional big array. val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t Return the one-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly one dimension. val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t Return the two-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly two dimensions. val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t Return the three-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly three dimensions. === Re-shaping big arrays === val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t reshape b [|d1;...;dN|] converts the big array b to a N -dimensional array of dimensions d1 ... dN . The returned array and the original array b share their data and have the same layout. For instance, assuming that b is a one-dimensional array of dimension 12, reshape b [|3;4|] returns a two-dimensional array b' of dimensions 3 and 4. If b has C layout, the element (x,y) of b' corresponds to the element x * 3 + y of b . If b has Fortran layout, the element (x,y) of b' corresponds to the element x + (y - 1) * 4 of b . The returned big array must have exactly the same number of elements as the original big array b . That is, the product of the dimensions of b must be equal to i1 * ... * iN . Otherwise, Invalid_argument is raised. val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t Specialized version of Bigarray.reshape for reshaping to one-dimensional arrays. val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t Specialized version of Bigarray.reshape for reshaping to two-dimensional arrays. val reshape_3 : ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t Specialized version of Bigarray.reshape for reshaping to three-dimensional arrays. OCamldoc 2014-06-09 Bigarray(3)
All times are GMT -4. The time now is 11:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy