You aren't reading the data properly into an array. I've changed the code to the following and it works (hopefully ):
Code:
/*My comments are in red*/
#include <stdio.h>
#include <stdlib.h>
/*You don't need math.h*/
typedef struct {
int size;
char name[21];
int boxnumber;
}item;
void swap(item *a, item *b){
item tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void bubbleSort(item a[], int size){
int i, j;
for (i=0; i<size-1; i++){
for (j=size-1; j>i; j--)
if (a[j].size < a[j-1].size)
swap(&a[j], &a[j-1]);
}
}
int main(void) {
int s,n;
int i;
item *array;
FILE *iFile;
iFile = fopen ("inputzou.txt","r");
fscanf (iFile, "%d, %d", &s, &n);
printf ("%d, %d\n", s, n);
array = calloc (n, sizeof(item)); /*Don't cast the return value of malloc or calloc*/
for (i=0;i<n;i++){ /*You're reading n values, not n+1, so the condition shouldn't be i<=n*/
array[i].boxnumber=0; /*initialize boxnumber to 0*/ /*using // comments isn't completely portable*/
fscanf(iFile, "%s %d", array[i].name, &array[i].size);
}
bubbleSort(array, n);
for (i=0; i<n; i++) {
printf("%s %d\n", array[i].name, array[i].size);
}
free(array);
fclose(iFile);
return 0;
}
Output:
295, 59
Sanctuary_Records 34
Kittie 38
Led_Zeppelin 42
Smashing_Pumpkins 42
Goldfinger 43
Rammstein 46
Static-X 47
Alexisonfire 48
Reset 48
Puddle_Of_Mudd 49
Taproot 49
U2 50
Abandoned_Pools 52
HIM 52
Godsmack 53
Garbage 54
Savage_Garden 59
30_Seconds_To_Mars 60
3_Doors_Down 61
Lifehouse 61
Hoobastank 64
Alient_Ant_Farm 65
I_Mother_Earth 66
Cold_Play 68
Nine_Inch_Nails 70
Weezer 71
The_White_Stripes 73
RageAgainstTheMachin 75
AFI 76
Nickelback 76
Trapt 77
The_Get_Up_KIds 80
Massive_Attack 81
Adema 82
System_of_a_down 86
Kidrock 91
Pink 110
Incubus 114
Nodoubt 117
Disturbed 118
Mudvayne 121
Nirvana 122
QueensOfTheStoneAge 123
Matthew_Good 125
The_Offspring 128
Green_Day 130
RedHotChiliPeppers 130
Staind 130
Deftones 138
Evanescence 139
SlipKnot 140
FooFighters 141
Papa_Roach 154
Linkin_park 181
Blink182 191
Pink_Floyd 202
Limp_Bizkit 234
Michael_Jackson 238
Korn 246