Sunday, 15 January 2012

c - Writing a function to print a string stored in an array -



c - Writing a function to print a string stored in an array -

im writing programme stores user-input strings in array. pass array function print sec element. realise programme crashes whenever print within function executed.

my sample code below:

main() { int num, count; char strstorage[10][10]; printf("\nenter how many strings: "); scanf( "%d" , &num); fflush(stdin); ( count = 0 ; count < num ; count++) { printf("enter string: "); gets(strstorage[count]); fflush(stdin); } //this works printf("%s", strstorage[2]); printmyarray(strstorage); } void printmyarray(char *myarray[ ]) { //this doesnt work printf("%s", myarray[2]); }

im doing in order larn how arrays passed functions. appreciate if can help me this.

thanks

the problem should pass double array double array, , not array of pointers.

void printmyarray(char *myarray[ ])

becomes

void printmyarray(char myarray[][10])

c arrays function

No comments:

Post a Comment