Can anyone please tell me what is the problem with this code?
There is no issue in the compilation of this code but after compilation when I enter the data of Array of Objects of structure, the data is not entered after one loop.
#include<stdio.h>
struct process{
char name;
int arv;
int burst;
}p[10];
int sort(struct process p[],int n){
int i,j;
struct process t;
for(i=0;i<n;i++){
for(j=0;j<n-1-i;j++){
if(p[j].arv>p[j+1].arv){
p[j]=t;
p[j]=p[j+1];
p[j+1]=t;
}
}
}
return 0;
}
int main(){
int i,n;
printf("Enter Number Of Processes");
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%c",&p[i].name);
scanf("%d",&p[i].arv);
scanf("%d",&p[i].burst);
}
sort(p,n);
for(i=0;i<n;i++){
printf("%c",p[i].name);
printf("%d",p[i].arv);
printf("%d",p[i].burst);
}
return 0;
}
See Question&Answers more detail:os