I tried this with an integer array and it worked.
#include<stdio.h>
main()
{
int c[5]; int i;
printf("\nEnter the integers (max.5):\n ");
for(i=0; i<=4; i++)
scanf("%d", &c[i]);
for(i=0; i<=4; i++)
display(&c[i]);
}
display(int *k)
{ printf("\nThe integers you entered are: %d", *k);
}
The output was:
Enter the integers (max.5):
1
4
3
7
6
The integers you entered are: 1
The integers you entered are: 4
The integers you entered are: 3
The integers you entered are: 7
The integers you entered are: 6
--------------------------------
Process exited after 3.182 seconds with return value 32
Press any key to continue . . .
But when i tried to pass a character array it gives a weird output and accepts only 3 characters.
#include<stdio.h>
main()
{
char c[5]; int i;
printf("\nEnter the characters (max.5): ");
for(i=0; i<=4; i++)
scanf("%c", &c[i]);
for(i=0; i<=4; i++)
display(&c[i]);
}
display(char *k)
{ printf("\nThe characters you entered are: %c", *k);
}
The output was:
Enter the characters (max.5):
a
s
f
The characters you entered are: a
The characters you entered are:
The characters you entered are: s
The characters you entered are:
The characters you entered are: f
--------------------------------
Process exited after 3.875 seconds with return value 34
Press any key to continue . . .
Question: I can't understand why this happens and why it is accepting only 3 characters. Where i am wrong? and what corrections should i do?