c Language structure access violation..

Asked 2 years ago, Updated 2 years ago, 43 views

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;



}

c

2022-09-22 19:19

1 Answers

node* temp; --> node temp;


2022-09-22 19:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.