i need to read a text from a file and pass it back to the main function and i am getting always 3 characters extra after EOF why is that happening ?
#include<stdio.h>
#include<string.h>
int activenw(char *);
void main()
{
char act_con[50];
int len,i;
len=activenw(act_con);
for(i=0;i<=len;i++)
{
printf("%c",act_con[i]);
}
}
int activenw(char *buff)
{
char ch="\0";
FILE *fp;
int i=0;
fp=fopen("abc.txt","r");
if(fp==NULL)
{
printf("Error opening a file :");
exit(0);
}
while((ch=fgetc(fp))!=EOF)
{
printf("%c",ch);
*buff=ch;
buff++;
i++;
}
fclose(fp);
return i;
}
is this implementation is correct?