S
Steve Zimmerman
This program compiles fine, but are there any hidden dangers
in it, or is it ok?
Experiment 1 ##################################################
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
int main()
{
struct pres {
char name[25];
struct pres *next;
};
struct pres *president;
president = (struct pres *)malloc(sizeof(struct pres));
strcpy(president->name, "George Washington");
president->next = (struct pres *)malloc(sizeof(struct pres));
printf("The first structure has been created:\n");
printf("president->name = %s\n", president->name);
printf("next structure address = %i\n", president->next);
return 0;
}
###################################################################
--Steve
in it, or is it ok?
Experiment 1 ##################################################
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
int main()
{
struct pres {
char name[25];
struct pres *next;
};
struct pres *president;
president = (struct pres *)malloc(sizeof(struct pres));
strcpy(president->name, "George Washington");
president->next = (struct pres *)malloc(sizeof(struct pres));
printf("The first structure has been created:\n");
printf("president->name = %s\n", president->name);
printf("next structure address = %i\n", president->next);
return 0;
}
###################################################################
--Steve