I wanted to store string values at a particular index of the character array using a while loop.
Condition for while loop termination : 'q' should be pressed to stop taking input
My Code so far
char s[100],in;
int count = 0;
printf("Enter individual names: \n");
scanf("%c",&in);
while (in != 'q')
{
s[count++] = in;
scanf("%c", &in);
}
printf("%d", count);
printf("%s" , s);
Input :
sam
tam
q
Output :
9����
I don't understand how can i store strings at an individual index of array and why is count giving me wrong value when it should have been 2.
Is there any other method to store string using while loop?
Thankyou so much.