0

c language

I want to ask how I can use %s to printf my string and scanf my string ? how do I modify? int main(void) { ASA_DEVICE_set(); int i; int A[5][2]; char B[5][1]; int temp2=0, temp3=0,j=0; char temp1; for(int i=0; i<4;i++){ printf("key in your name :\n"); scanf("%s",&B[i][0]);} for(int i=0; i<4;i++){ printf("key in your id :\n"); scanf("%d",&A[i][0]);} for(int i=0; i<4;i++){ printf("key in your score :\n"); scanf("%d",&A[i][1]); } for(int k=0;k<4;k++) { for( int j = k; j < 4; j++) { if( A[j][1] < A[k][1] ) { temp1 = B[j][0]; B[j][0] = B[k][0]; B[k][0] = temp1; temp2 = A[j][1]; A[j][1] = A[k][1]; A[k][1] = temp2; temp3 = A[j][0]; A[j][0] = A[k][0]; A[k][0] = temp3; } } } for(int i=0; i<5;i++){ printf("name:%s id:%d score:%d\n",B[i][0],A[i][0],A[i][1]); } }

18th Jul 2019, 5:04 AM
翁shuai
翁shuai - avatar
1 ответ
0
Your printf / scanf logic is wrong as what you try to read / write is a character and not a string. Is it what you wanted to do ?
5th Dec 2019, 10:27 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar