coderyc
03-22-2010, 07:12 PM
Hello,
I am getting a bus error when I run the following code:
I dont understand why I get a bus error??
#include <stdio.h>
#define MAX_ENTRIES 100
typedef struct ContactRecord
{
char name[16]; /*structure member*/
unsigned char number[20]; /*structure member*/
}Contact; /*Contact is a structure variable of type ContactRecord*/
static Contact ContactTable[MAX_ENTRIES];
void edit_record(char *, char *);
main()
{
char name [] = "johnsmith";
char number[] = "1234567891234567890";
edit_record(&name, &number);
}
void edit_record(char *ptrname, char *ptrnumber)
{
int i=0, j=0;
for (j = 0; j<= 16; j++)
ContactTable[i].name[j] = ptrname[j];
for (j=0; j<= 20; j++)
ContactTable[i].number[j] = ptrnumber[j];
for (j = 0; j<= 16; j++)
printf("%s\n",ContactTable[i].name[j]);
}
I am getting a bus error when I run the following code:
I dont understand why I get a bus error??
#include <stdio.h>
#define MAX_ENTRIES 100
typedef struct ContactRecord
{
char name[16]; /*structure member*/
unsigned char number[20]; /*structure member*/
}Contact; /*Contact is a structure variable of type ContactRecord*/
static Contact ContactTable[MAX_ENTRIES];
void edit_record(char *, char *);
main()
{
char name [] = "johnsmith";
char number[] = "1234567891234567890";
edit_record(&name, &number);
}
void edit_record(char *ptrname, char *ptrnumber)
{
int i=0, j=0;
for (j = 0; j<= 16; j++)
ContactTable[i].name[j] = ptrname[j];
for (j=0; j<= 20; j++)
ContactTable[i].number[j] = ptrnumber[j];
for (j = 0; j<= 16; j++)
printf("%s\n",ContactTable[i].name[j]);
}