im new to c programming.i tried to get char inputs and assign them to char array.and then i printed that array.but when printing it shows another characters also after given chararcters.if can somebody help me to solve this il be very great ful to you.(pleas show me how to make char array from input)
my code is
Code:
#include<stdio.h>
#define MAX 100
main()
{
char s[MAX];
int c;
int i=0;
//assign to char array
while((c=getchar())!='\n')
{
s[i]=c;
i++;
}
//print char array
int p=0;
while(s[p]!='\0')
{
printf("%c",s[p]);
p++;
}
}
whe i give input as example i wrote in command prompt "rukshan"
output is "rukshan#$^&*^"
please help me
thanx
output is