Thread: returning multiple arrays from one function to another

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Definition:
    Code:
    int rr_counts(struct DataList* ArrayOne, size_t SizeOfArrayOne, struct DataList* ArrayTwo, size_t SizeOfArrayTwo)
    The calling:
    Code:
    rr_counts(my_array1, sizeof(my_array1), my_array2, sizeof(my_array2));
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    I don't know what is the job of
    rr_counts(xx_r,yy_r,zz_r,nrows2,nrows3,rad);
    What you can do, I suppose is:
    Code:
    void third_read_file(long double *rad, int *nrows3)
    {
    	some code
    	.
    	.
    	.
    	*nrows3=something;
    	rad=(long double *)malloc(sizeof(long double) * *nrows3);
    
    }
    
    void rr_counts(struct DataList *data_list_d,long double *rad, int nrows3)
    {
    	// here 	xx_r[i] = data_list->data[i].x
    	// here 	yy_r[i] = data_list->data[i].y
    	// here 	zz_r[i] = data_list->data[i].z
    	// here		nrows2  = data_list->size 
     
    }
    int main(void)
    {
        struct DataList data_list_d, data_list_r;
    	int nrows3;
    	long double *rad;
    
        if (readFile("file1", &data_list_d))
        {
            printf("there are %d in FIRST data\n", data_list_d.size);
            free(data_list_d.data);
        }
    
        if (readFile("file2.dat", &data_list_r))
        {
            printf("there are %d in random data\n", data_list_r.size);
            free(data_list_r.data);
        }
    
        /* The old rr_count 
    	rr_counts(xx_r,yy_r,zz_r,nrows2,nrows3,rad); */
    
        /* The code for the third file read is left as an exercise for the reader. */
    	third_read_file(rad,&nrows3);
    	rr_counts(data_list,rad,nrows3); 
    
    
        return 0;
    }

  3. #18
    Registered User
    Join Date
    Aug 2010
    Posts
    12
    I got it sorted -

    so what i did was (for anyone as inept as me):

    for the function rr_counts:

    Code:
    int rr_counts(struct DataList data_list_r) {
    
    for(j=0; j<51; j++) 
        {
         	printf("rr test= %Le\n",data_list_r.data[j].x);
    
        }	
    
    .
    .
    .
    }
    then when called the function in int main:

    Code:
    rr_counts(data_list_r);
    as easy as that!

  4. #19
    Registered User
    Join Date
    Aug 2010
    Posts
    12
    Quote Originally Posted by giove View Post
    I don't know what is the job of
    rr_counts(xx_r,yy_r,zz_r,nrows2,nrows3,rad);
    What you can do, I suppose is:
    Code:
    void third_read_file(long double *rad, int *nrows3)
    {
    	some code
    	.
    	.
    	.
    	*nrows3=something;
    	rad=(long double *)malloc(sizeof(long double) * *nrows3);
    
    }
    
    void rr_counts(struct DataList *data_list_d,long double *rad, int nrows3)
    {
    	// here 	xx_r[i] = data_list->data[i].x
    	// here 	yy_r[i] = data_list->data[i].y
    	// here 	zz_r[i] = data_list->data[i].z
    	// here		nrows2  = data_list->size 
     
    }
    int main(void)
    {
        struct DataList data_list_d, data_list_r;
    	int nrows3;
    	long double *rad;
    
        if (readFile("file1", &data_list_d))
        {
            printf("there are %d in FIRST data\n", data_list_d.size);
            free(data_list_d.data);
        }
    
        if (readFile("file2.dat", &data_list_r))
        {
            printf("there are %d in random data\n", data_list_r.size);
            free(data_list_r.data);
        }
    
        /* The old rr_count 
    	rr_counts(xx_r,yy_r,zz_r,nrows2,nrows3,rad); */
    
        /* The code for the third file read is left as an exercise for the reader. */
    	third_read_file(rad,&nrows3);
    	rr_counts(data_list,rad,nrows3); 
    
    
        return 0;
    }

    Thanks for your suggestion i'll give that some thought! i just posted how i sorted it with your previous suggestion.

    cheers
    R.

  5. #20
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    function

    in your function prototype and implementation (the working parts of the function) you have to list the data types and appropriate names for them, in the function call you have to just write the names of types to pass that match the types declared in the prototype, the number of parameters you pass must also match prototype, you only need to declare variables local to the function if u think u need them to perform operations in the function
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random number gen difficult
    By Chris_1980 in forum C Programming
    Replies: 21
    Last Post: 04-30-2010, 09:02 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. returning char arrays!!!!
    By bobthebullet990 in forum C Programming
    Replies: 2
    Last Post: 03-30-2006, 07:05 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. c function returning multiple values
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-23-2001, 10:09 AM

Tags for this Thread