current position:Home>Let's see what's wrong. My code will output one less country

Let's see what's wrong. My code will output one less country

2022-02-03 00:09:02 CSDN Q & A

#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n;
scanf("%d",&n);
char str1[n][20];
char t[20];
if(n>20){printf("Data Error");return 0;}
else {for(i=0;i<n;i++){gets(str1[i]);}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(strcmp(str1[i],str1[j])>0){
strcpy(t,str1[i]);
strcpy(str1[i],str1[j]);
strcpy(str1[j],t);
}
}
}
}
for(i=0;i<n;i++){
printf("%s\n",str1[i][20]);
}
return 0;
}

img


img




Refer to the answer 1:

img


Change to

i<=n




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030009004737.html

Random recommended