
Patrick B. answered 08/26/20
Math and computer tutor/teacher
What are the compiler errors you are getting???
you have a semicolon after the condition in the if statement
inside the for loop. That is not necessarily a compiler error,
but definitely a bug
in the statement maxlen = strlen(a[0]), you must pass
the address!!! That is a compiler error...
Why not just do strlen(a); ????
The if-statement in the for loop is incorrect...
a[i] is the ith character in the string, which
is also a compiler error as strlen, again, expects
an address. Again, do strlen(a)
You did it again, a THIRD time, in the printf
statement.
============================================
#include <stdio.h>
#include <string.h>
#define MAX_LEN (1024)
void Go()
{
int N=-1;
int iLoop=0;
char str[MAX_LEN];
char inbuff[MAX_LEN];
while (N<0)
{
printf(" How many strings ???? :>");
scanf("%d",&N);
}
int maxStrLen= -1;
for (iLoop=0; iLoop<N; iLoop++)
{
printf(" Input the string :>");
scanf("%s",inbuff);;
int strLen = strlen(inbuff);
if (strLen>maxStrLen)
{
maxStrLen = strLen;
strcpy(str,inbuff);
}
}
printf(" The longest string is >%s< with length %d \n",str,maxStrLen);
}
int main()
{
Go();
}