Hejo!
ostatnio uzywam Visual Studio 2013 w wersji Pro. Napisalem sobie funkcje do stosu i prosilbym o sprawdzenie. Dodam ze gdy odpale recznie skompilowane exeki to nie ma zadnego problemu. Natomiast gdy w trybie debug zaraz po kompilacji program sie zaladuje i po wpisaniu 2[enter] i jeszcze raz dostaje blad:
Dodatkowo po wywaleniu tego bledu program sam sie nie zamyka. Robie to recznie i konsola sie zamyka po dobrych 3-4 sekundach. Dlaczego?
o co chodzi?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct lista
{
int key;
struct lista *next;
};
void menu()
{
printf("\tMenu: \n1. Push (+) \n2. Pop (-) \n3. IsEmpty() \n4. First \n5. Czyszczenie \n6. Exit\n\n\tWybor: ");
}
struct lista *Push(struct lista *head, int liczba)
{
struct lista *nowy = (struct lista*)malloc(sizeof(struct lista));
nowy->next = NULL;
nowy->key = liczba;
if (head != NULL)
nowy->next = head;
return nowy;
}
struct lista *Pop(struct lista *head)
{
if (head == NULL)
printf("ERROR Stos jest pusty!\n");
else
{
struct lista *temp = head;
head = head->next;
printf("Usuwam %d\n", temp->key);
free(temp);
temp = NULL;
return head;
}
}
void First(struct lista *head)
{
if (head != NULL)
printf("%d \n", head->key);
else
printf("Nic tu nie ma\n\n");
}
bool IsEmpty(struct lista *head)
{
if (head == NULL)
return true;
else
return false;
}
void Clear(struct lista *head)
{
while (IsEmpty(head)==false)
Pop(head);
}
int main()
{
struct lista *head = NULL;
Push(head, 3);
Push(head, 2);
Push(head, 1);
int wybor = 0, wartosc;
while (wybor != 6)
{
menu();
scanf("%d", &wybor);
switch (wybor)
{
case 1:
printf("\n\tWpisz wartosc: ");
scanf("%d", &wartosc);
head = Push(head, wartosc);
break;
case 2:
head=Pop(head);
break;
case 3:
(IsEmpty(head) == true) ? printf("Stos jest pusty\n") : printf("Stos nie jest pusty\n");
break;
case 4:
First(head);
break;
case 5:
Clear(head);
break;
case 6:
EXIT_SUCCESS;
}
printf("_____________________________________\n\n");
}
system("PAUSE");
return 0;
}
dodanie obrazka to załączników i treści
- @furious programming