last string is always the answer
Code:
#include <stdio.h>
#include <string>
#include "simpio.h"
#include "genlib.h"
#include "strlib.h"
int main() {
string longestString, current;
int work = 0;
int possible;
int greatest;
printf("please enter a list of strings, end the list with the word 'end'");
printf("enter: ");
current = GetLine();
longestString = current;
greatest = StringLength(current);
while(work == 0) {
printf("enter: ");
current = GetLine();
if (StringEqual(current, "end"))
{
work++;
}
else if (StringLength(current) > greatest)
{
greatest = possible;
longestString = current;
}
else {
}
}
printf("the longest string is: %s\n", current);
}
it should put out the longest string but it always says end is longest...wtf?