Hello. When i am using i read text from file and when i use strlen function I always getting sting length longer by 1. Is there any alternative way to count string length except -1 because I need to find shortest line in .txt file.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char filename[50];
char str[100];
int a,min=0;
printf("Enter file name \n");
scanf("%s",&filename);
if ((fp=fopen(filename,"r"))==NULL)
{
printf("Error \n");
system("pause");
exit(1);
}
while (!feof(fp))
{
fgets(str, 99, fp);
a=(strlen(str));
if (a=1)
if (min=0)
min=a;
else
if (min<a)
min=a;
}
printf ("%d", min);
system("pause");
}
of course this isn't complete code because i faced this problem.