| | |
Passing a pointer to an array.
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for C
#include ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






