| | |
sending address of multidimensional char array to a function
![]() |
•
•
Join Date: Oct 2006
Posts: 60
Reputation:
Solved Threads: 0
how do i send a multidimensional char array to a function.
i try assigning values like this :
and then sending it like this:
when i compile it gives a warning:
and when i debug with gdb debugger, just before entering into WriteValues function, it gives segmentation fault. It never enters in.
why?
WriteValues function is here:
thanx.
i try assigning values like this :
C Syntax (Toggle Plain Text)
char ChrArrayAttributes[2][20]; strcpy(ChrArrayAttributes[0],"TIME"); strcpy(ChrArrayAttributes[1],"IDENT");
and then sending it like this:
C Syntax (Toggle Plain Text)
WriteValues("/pp1/reb","RADR",ChrArrayAttributes);
when i compile it gives a warning:
C Syntax (Toggle Plain Text)
Test.c:115: warning: passing arg 3 of `WriteValues' from incompatible pointer type
and when i debug with gdb debugger, just before entering into WriteValues function, it gives segmentation fault. It never enters in.
why?
WriteValues function is here:
C Syntax (Toggle Plain Text)
void WriteValues(char * sDBName, char * sTableName, char * ChrArrayAttr[]) { int i = 0; /* Trying to write values TIME and IDENT to the screen */ for(i=0; i<2; i++) { printf("ChrArrayAttr[%d]=%s\n",i,ChrArrayAttr[i]); } }
thanx.
> void WriteValues(char * sDBName, char * sTableName, char * ChrArrayAttr[])
There are several compatible declarations for passing a 2D array - one of them is really easy.
The first is dead easy, you simply copy/paste the declaration of the array you want to pass, into the parameter position of the function you want to pass it to.
The occasional compiler / tool will fuss over the specification of the major dimension, but it's easy to remove with a quick edit.
As with any other array parameter, you just use the array name (like you do now).
There are several compatible declarations for passing a 2D array - one of them is really easy.
C Syntax (Toggle Plain Text)
void WriteValues(char *sDBName, char *sTableName, char ChrArrayAttributes[2][20] ) void WriteValues(char *sDBName, char *sTableName, char ChrArrayAttributes[][20] ) void WriteValues(char *sDBName, char *sTableName, char (*ChrArrayAttributes)[20] )
The occasional compiler / tool will fuss over the specification of the major dimension, but it's easy to remove with a quick edit.
As with any other array parameter, you just use the array name (like you do now).
![]() |
Similar Threads
- One line of code copy char array using pointers (C++)
- Return a 2D array from a function (C++)
- C++ pass 2d array into function (C++)
- adding data into an char array (C++)
- array function operation (C++)
- two-dimensional char array (Java)
- Using .length() with multidimensional char array ? (Help) (C)
Other Threads in the C Forum
- Previous Thread: Is this program valid???if yes then tell how?
- Next Thread: debugging shared object
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork function getlasterror getlogicaldrivestrin givemetehcodez global grade gtkgcurlcompiling gtkwinlinux hacking hardware highest histogram ide include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing segmentationfault sequential single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






