Answer the question
In order to leave comments, you need to log in
C program question
There is the following piece of code.
If we enter “1”, the program execution ends for some reason, the message “Segmentation error” is displayed.
In any other case, everything is ok.
If we write int act = X, act, value; similarly - if X == 1, then "Segmentation error", otherwise - everything is OK.
Compiler gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
What could be the problem?
...
int main(int argc, char* argv[])
{
int act, act2, value;
printf("Выберите действие:\n1. Вывод списка\n2. Добавить элемент в список\n0. Выйти из программы\n->");
scanf("%d", &act);
printf("Введенное значение:\n%d\n", act);
...
}
Answer the question
In order to leave comments, you need to log in
Naturally, the error occurs in return (item->next == NULL)? ten;
when you enter 1, item contains NULL, and you are trying to dereference it and refer to a non-existent offset "next"
On which line is the error thrown? Exactly in this piece of code?
I checked your piece of code on gcc (CentOS) - no errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question