+ 3

whay does this warningsay?

https://code.sololearn.com/cUS4P16ZhQGC/#c #include <stdio.h> int sort(int arr[], int b); int main() { int m, n; scanf("%d%d", &m, &n); int arr[20][20]; for(int i=0; i<m; i++) for(int j=0; j<n; j++) scanf("%d", &arr[i][j]); for(int i=0; i<m; i++){ sort(arr+i, n); } for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ printf("%d ", arr[i][j]); } printf("\n"); } return 0; } int sort(int arr[], int n){ int temp= 0; for(int i=0; i<n-1; i++){ for(int j=0; j<n-1-i; j++){ if(arr[j]> arr[j+1]){ temp= arr[j]; arr[j]= arr[j+1]; arr[j+1]= temp; } } } return 0; } /*Following is the warning that occured but the output is correct for all inputs. what is this... ./Playground/file0.c: In function 'main': ./Playground/file0.c:11:17: warning: passing argument 1 of 'sort' from incompatible pointer type [-Wincompatible-pointer-types] 11 | sort(arr+i, n); | ~~~^~ | | | int (*)[20] ./Playground/file0.c:2:14: note: expected 'int *' but argument is of type 'int (*)[20]' 2 | int sort(int arr[], int b); | ~~~~^~~~~ */

5th Aug 2020, 3:00 AM
Tom
Tom - avatar
6 ответов
+ 4
Yeah But Problem is Solve. Thank you for Sharing you Programm Bug.
5th Aug 2020, 3:29 AM
Mohammed Qadir Khan
Mohammed Qadir Khan - avatar
+ 4
Use pointer While calling sort sort(*(arr+i), n) ;
5th Aug 2020, 7:07 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Problem solve #include <stdio.h> int sort(int arr[], int b); int main() { int m, n; scanf("%d%d", &m, &n); int arr[20][20]; for(int i=0; i<m; i++) for(int j=0; j<n; j++) scanf("%d", &arr[i][j]); for(int i=0; i<m; i++){ sort(arr[i], n); } for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ printf("%d ", arr[i][j]); } printf("\n"); } return 0; } int sort(int arr[], int n){ int temp= 0; for(int i=0; i<n-1; i++){ for(int j=0; j<n-1-i; j++){ if(arr[j]> arr[j+1]){ temp= arr[j]; arr[j]= arr[j+1]; arr[j+1]= temp; } } } return 0; } //you define sort(arr + i, n ) --> wrong you not add array with number you need pass number in array like below sort(arr[i] , n) Problem solve you declare above sort function like i defined.
5th Aug 2020, 3:19 AM
Mohammed Qadir Khan
Mohammed Qadir Khan - avatar
+ 2
Mohammed Qadir khan thanks Has the error occured because arr+i is a pointer and arr[i] is an array..? Sort() expects an array but a pointer is passed is that right?
5th Aug 2020, 3:27 AM
Tom
Tom - avatar
+ 2
Thanks
5th Aug 2020, 3:30 AM
Tom
Tom - avatar
+ 2
My Pleasure.
5th Aug 2020, 3:31 AM
Mohammed Qadir Khan
Mohammed Qadir Khan - avatar