Problem with 2d array (as argument type)

can anyone help me to look at the code and what is the problem is????
No output at all!


#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <mysql.h>

const static int NUM_RECORD = 3000;


void FUNC(char name[][30])
{
name[0][30] = "John Tennon";
name[1][30] = "Bod Tender";
name[2][30] = "Lemon Tennon";

}
int main()
{
char name[NUM_RECORD][30];
FUNC(name);

int a;
for (a=0; a<NUM_RECORD; a++)
printf("%s\n", name[a][30]);

return 0;

}


You should pay attention to what you're compiler is telling you when you compile. Do not ignore warnings if you don't know why they are occuring.

name[index][30] is beyond the scope of name[index]. Valid indices for an array are 0 to size-1 where size is the number of elements in an array.

name[index1][index2] is of type char. You're trying to teat it as if it is a string.

In FUNC you attempt to assign the address of several string literals to a char.

This is a C++ forum, not a C forum.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>

#define NUM_RECORD 10
#define NAME_LENGTH 30

void FUNC( char name[][NAME_LENGTH] )
{
    strcpy(name[0], "John Tennon") ;
    strcpy(name[1], "Bod Tender") ;
    strcpy(name[2], "Lemon Tennon") ;  
}

int main(void)
{
    char name[NUM_RECORD][NAME_LENGTH] = {{0}};
    FUNC(name) ;

    for ( int i=0; i < NUM_RECORD; ++i )
        printf("%s\n", name[i]); 
}


http://ideone.com/6blWT1
Thank you cire....

I solved it with u code. Output can see right now.. TQ
Topic archived. No new replies allowed.