It's simply a code that creates a structure and receives a value.
I don't know why access violations occur
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_STACK_SIZE 100
#pragma warning(disable: 4996)
typeef structure_element {/*data structure*/
int key;
char name[20];
char address[100];
}element;
typedef struct _node {
struct _node *leftChild;
element data;
struct _node *rightChild;
}node;
void push(node *pushnode);
node *stack[MAX_STACK_SIZE];
int top = 0;
int main(void)
{
char string[256];
char *tok;
node* temp;
memset(&temp, 0, sizeof(temp));
printf("Enter the material (college, name, address) to insert: ");
gets_s(string, 256);
tok = strtok(string, " ");
temp->data.key = atoi(tok);//Exception thrown : Write access violation...................
tok = strtok(NULL, " ");
strcpy(temp->data.name, tok);
tok = strtok(NULL, "");
strcpy(temp->data.address, tok);
temp->leftChild = temp->rightChild = NULL;
}
node* temp;
--> node temp;
© 2024 OneMinuteCode. All rights reserved.