c++ - How to read input from header file? -



c++ - How to read input from header file? -

i have header file abc.h

//abc.h unsigned int *get(void) { static unsigned int input[] = { 1, 2, 2, 4, 5, 6, 7 }; homecoming input; }

now, want read input(from header file,not text file) main cpp file xyz.cpp

i thinking of using array access these elements,but don't think work.

int arr[6]; arr=get();

the first element number of test cases n,the sec , 3rd element dimensions of 2-d array , rest of elements values of 2-d array.so need input value of n,rows,columns , values 2d array arr[rows][columns]

any ideas on how can accomplish this?

edit: can't figure out why question getting downvoted. agree not implementation,but have been given input header file , can read info through header file!!

if able compile programm file, not need read anything. array , values compiled programm , can access them right in place

your xyz.cpp file should like:

#include "abc.h" // given abc file located in same directory int main(){ unsigned int * myarrayptr = get(); // here comes processing and, if want, reading values array; unsigned int numberofcases = myarrayptr[0]; unsigned int * dimensionsarrayptr = myarrayptr + 1; unsigned int xarraysize = dimensionsarrayptr[0]; unsigned int yarraysize = dimensionsarrayptr[1]; // , etc. // interesting part represent values 2 dimensional array // left :) homecoming 0; }

also, should remeber trick work because array in header file declared static. otherways programm have undefined behavior.

one more also. if function body defined in header file, should declare inline. long header included on 1 cpp file - right. when included more 1 code file, already defined linker error.

i recommend larn more pointers in cpp. article fine plenty http://www.cplusplus.com/doc/tutorial/pointers/

about static keyword - understand illustration - there fine reply on the static keyword , various uses in c++

c++ c input header-files

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -