Well I had an assignment to sort an array of structures so i went about trying but always some strange fault come about. Now not only does the main program fail but also another program. What i want to know is that is it a problem in my code, or something else is happening?? Below are the two programs!!
on running it it gives that "stack fault in module toolhelp.dll at 0001:2239"
Again the simple program to retrieve something from an array of structure fails saying "general protection exception 0x2557:0x37EB processor fault"
Code:
#include<stdio.h> #include<conio.h> #include<string.h> main() { struct boy { char name[100]; int marks; }; struct boy a[100]; int no,i,l,m,k,t; char nam[100]; printf("Enter no of students"); scanf("%d", &no); for(i=0;i<no;i++) { printf("Enter Name"); gets(a[i].name); printf("Enter Marks"); scanf("%d", a[i].marks); } for(l=1;i<=no-1;l++) { for(m=0;m<no-l;m++) { if(a[m].marks>a[m+1].marks) { strcpy(nam,a[m].name); strcpy(a[m].name,a[m+1].name); strcpy(a[m+1].name,nam); t=a[m].marks; a[m].marks=a[m+1].marks; a[m+1].marks=t; } } } for(k=0;k<no;k++) { puts(a[k].name); printf("%d", a[k].marks); } getch(); return 0; }
Again the simple program to retrieve something from an array of structure fails saying "general protection exception 0x2557:0x37EB processor fault"
Code:
#include<stdio.h> #include<conio.h> main() { struct book { int pages; int no; }; struct book b[100]; int i,n,j; scanf("%d", &n); for(i=0;i<n;i++) { printf("Enter pages"); scanf("%d", b[i].pages); printf("Enter Book Number"); scanf("%d", b[i].no); } for(j=0;j<n;j++) { printf("Pages are %d", b[j].pages); printf("Number is %d", b[j].no); } getch(); return 0; }
Comment