1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <string.h>
4. int main(){
5. int n;
6. int i;
7. printf("Enter size of array : ");
8. scanf("%d", &n);
9. char *arr = (char *)malloc(n*sizeof(char));
10. printf("Enter string : ");
11. gets(arr);
12. for(i=strlen(arr)-1; i>=0; i--){
13. printf("%c", *(arr+i));
14. }
15. return 0;
16. }
When i'm trying to execute this code it's only ask for Enter size of array(7th line). After hiting the enter key, this program ends. It does not execute 10th line. It prints 'enter string :' in line 10. but it also ends the program with that. Therefore i cant insert elements into my array. But if i use getchar() after scanf() function in line 8, it works fine. Please explain the reason for this problem.
Thank you so much !