|
From: Nurhidayat <dh...@ma...> - 2001-09-20 05:09:46
|
I've found bugs(?) when trying to code linked list record. Compiler cannot
allocated base type variable within structure, but array of char work fine.
Here is I simplified code:
#include <stdlib.h>
#include <stdio.h>
struct mystruct {
char name[8];
int age;
};
int main()
{
mystruct *ptr; //test dynamic allocation
int *page;
ptr = new mystruct; //compiler must allocate memory
page = new int;
printf("Address of name : %p\n", ptr->name); //allocated
printf("Address of age : %p\n", ptr->age); //give us null pointer, why?
printf("Address of page : %p\n", page); //allocated (for comparison)
//so ...
printf("Enter name:"); scanf("%s", ptr->name); //success
printf("Enter age :"); scanf("%s", ptr->age); //raised error!!!
delete ptr;
delete page;
system("PAUSE");
return 0;
}
___Nurhidayat___
|