Thread: Help with array

  1. #1
    Unregistered
    Guest

    Help with array

    Hi everyone,
    I am writing this function that takes an array and 4 ints as parameters(ros, clos, locx and loc y); It prints out the array accoprding to the number of cols and rows, Now I want it to return the value in the location specified by x and y But I can't figure out how;
    Here is what I've done so far, I would appreciate any help I can get. My main question is how do I figure out the index.
    Thanks,

    #include<stdio.h>
    #include"info.h"

    Info extract(float* sky,int rows,int cols,int x,int y)
    {

    int i;

    for(i=0;i<rows*cols;i++)
    {
    printf("%6d\n",sky[i]);
    if((i + 1) % cols == 0 && i > 0)
    printf("\n");

    }

    printf("\n");

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    If you are using rows and columns you might want to think about using a double float array.
    Code:
    float info_extract(float** sky, int row, int col, int x, int y){
    //print rows and columns
    return sky[x][y];
    }
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Unregistered
    Guest
    I know, but the point is to learn how to manipulate arrays.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well that really depends on how you intend to call this function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM