| | |
Passing a pointer to an array.
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 6
Reputation:
Solved Threads: 0
Hi.
Objective: Write a program that declares a 12*12 array of characters. Place Xs in every other element. Use a pointer to the array to print the values to the screen in a grid format.
Listed below is my non-functional attempt. Any help would be most appreciated.
Thanks,
Molly
Objective: Write a program that declares a 12*12 array of characters. Place Xs in every other element. Use a pointer to the array to print the values to the screen in a grid format.
Listed below is my non-functional attempt. Any help would be most appreciated.
Thanks,
Molly
C Syntax (Toggle Plain Text)
#include <stdio.h> void display_grid( char** g ); int i, j; int main( void ) { char grid[12][12]; display_grid( &grid[0][0] ); return 0; } void display_grid( char** g ) { for( i = 0; i < 12; i++ ) { for( j = 0; j < 12; j++ ) { g[i][j] = 'O'; } } for( i = 0; i < 12; i++ ) { for( j = 0; j < 12; j++ ) { if( j % 2 == 1 ) { g[i][j] = 'X'; } printf( " %c ", g[i][j] ); } printf( "\n" ); } }
![]() |
Similar Threads
- c language problm, how to pass pointer to a function (C)
- Pointer to array (C++)
- Nice easy one for you all... passing arrays to functions in C (C++)
- Passing a Value between an Array and Another Function (C++)
- Passing a matrix from main function to user defined function. (C++)
- total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast" (C++)
- C++ pass 2d array into function (C++)
Other Threads in the C Forum
- Previous Thread: assigning a char pointer to a struct member of similar type ........
- Next Thread: our very own OS
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






