I have a txt file includes 10000 passwords in it.I am trying to sort the passwords by length.Here is my function:
void bubbleSortASC(){
int n = 9999;
int i,j ;
char pw[n];
char temp;
FILE* fp;
fp = fopen("C:\\Users\\inanm\\Desktop\\project-work-2018555459\\10-million-password-list-top\\10000.txt", "r");
//fgets(pw, n , fp);
while(!feof(fp)){
fgets(pw, n , fp);
//printf("%s",pw);
}
for(i = 0; i < n-1;i++) {
for(j = i+1; j < n; j++){
if(strlen(pw[i]) > strlen(pw[j])){
strcpy(temp,pw[i]);
strcpy(pw[i],pw[j]);
strcpy(pw[j],temp);
}
}
}
fclose(fp);
printf("Ascending order of first 10 passwords are : \n");
for (i = 0; i < 10; i++){
printf("%s ", pw[i]);
}
printf("\n");
}
I've got no error but my output is empty.Can you help me to find the problem