Operating System concept 1 - Segmentation fault using C code

preview_player
Показать описание
Understanding segmentation fault using C code
Рекомендации по теме
Комментарии
Автор

Exactly to the point... Good explaination ...

rohanghige
Автор

Dear Harshit SIR...i've been trying to execute this code on ubuntu version 16...here is the code and i get a segmentation fault everytime i try to compile it...sir ...please help me...please tell me the thing that is wrong with the code...please sir ...here's the code
#include<stdio.h>
#include<string.h>

void print(int *num, int n)
{
int i;
for ( i = 0 ; i < n ; i++)
printf("%d ", num[i]);
printf("\n");
}
int main()
{
int num[N];
int *ptr;
int temp;
int i, n, j;
printf("\nHow many number you want to enter: ");
scanf("%d", &n);
printf("\nEnter a list of numbers to see all combinations:\n");
for (i = 0 ; i < n; i++)
scanf("%d", &num[i]);
for (j = 1; j <= n; j++) {
for (i = 0; i < n-1; i++) {
temp = num[i];
num[i] = num[i+1];
num[i+1] = temp;
print(num, n);
}
}
return 0;
}...i hope you'll help me as soon as possible ...thanking you

reverb_mafia
Автор

thank you sir for your good explanation, i got the same problem, but my os is linux mint and everytime i use malloc or something like that i got segmentation fault idk why, but now i understand the basic thank you

vitalisemanuelsetiawan
join shbcf.ru