Click here to Skip to main content
15,899,937 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Emrah Duatepe14-Jan-18 23:37
Emrah Duatepe14-Jan-18 23:37 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Jochen Arndt15-Jan-18 0:20
professionalJochen Arndt15-Jan-18 0:20 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Emrah Duatepe15-Jan-18 0:30
Emrah Duatepe15-Jan-18 0:30 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Jochen Arndt15-Jan-18 0:48
professionalJochen Arndt15-Jan-18 0:48 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Emrah Duatepe15-Jan-18 0:39
Emrah Duatepe15-Jan-18 0:39 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Jochen Arndt15-Jan-18 0:54
professionalJochen Arndt15-Jan-18 0:54 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Emrah Duatepe15-Jan-18 1:10
Emrah Duatepe15-Jan-18 1:10 
AnswerRe: I couldn't think a good title for this.Simple question Pin
Richard MacCutchan14-Jan-18 21:39
mveRichard MacCutchan14-Jan-18 21:39 
GeneralRe: I couldn't think a good title for this.Simple question Pin
Emrah Duatepe14-Jan-18 21:45
Emrah Duatepe14-Jan-18 21:45 
Questionfinding longest word Pin
Anonygeeker10-Jan-18 22:05
Anonygeeker10-Jan-18 22:05 
AnswerRe: finding longest word Pin
Richard MacCutchan10-Jan-18 22:25
mveRichard MacCutchan10-Jan-18 22:25 
GeneralRe: finding longest word Pin
Anonygeeker10-Jan-18 22:40
Anonygeeker10-Jan-18 22:40 
GeneralRe: finding longest word Pin
Richard MacCutchan10-Jan-18 22:46
mveRichard MacCutchan10-Jan-18 22:46 
GeneralRe: finding longest word Pin
Anonygeeker10-Jan-18 23:00
Anonygeeker10-Jan-18 23:00 
AnswerRe: finding longest word Pin
Jochen Arndt10-Jan-18 22:45
professionalJochen Arndt10-Jan-18 22:45 
AnswerRe: finding longest word Pin
CPallini10-Jan-18 23:31
mveCPallini10-Jan-18 23:31 
Try
C
#include <stdio.h>

enum State
{
  INSIDE_BLANKS,
  INSIDE_WORD
};

void find_longest_word( const char * a, const char ** pps, const char ** ppe);

int main()
{
  const char * foo = "alpha  beta gamma delta epsilon   ";

  const char *ps, *pe;

  find_longest_word( foo, &ps, &pe);

  if ( pe-ps > 0)
  {
    printf("longest word length = %ld\n", (pe-ps));
    while (ps != pe)
    {
      printf("%c", *ps);
      ++ps;
    }
    printf("\n");
  }
  return 0;
}

void find_longest_word( const char * a, const char ** pps, const char **ppe)
{
  const char * ps = a;
  const char * pe = a;
  *pps = *ppe = a;

  enum State state = INSIDE_BLANKS;

  while ( *a != '\0')
  {
    if ( state == INSIDE_BLANKS)
    {
      if ( *a != ' ')
      {
        state = INSIDE_WORD;
        ps = a;
      }
    }
    else // inside word
    {
      if ( *a == ' ')
      {
        pe = a; 
        if ( pe - ps > *ppe - *pps)
        {
          *pps = ps;
          *ppe = pe;
        }
        state = INSIDE_BLANKS;
      }
    }
    ++a;
  }
  // special handling of (possible) last word
  if ( state == INSIDE_WORD)
  {
    if ( pe - ps > *pps - *pps)
    {
      *pps = ps;
      *ppe = pe;
    }
  }
}

QuestionCString to CByteArray Pin
_Flaviu9-Jan-18 0:16
_Flaviu9-Jan-18 0:16 
AnswerRe: CString to CByteArray Pin
Jochen Arndt9-Jan-18 1:11
professionalJochen Arndt9-Jan-18 1:11 
AnswerRe: CString to CByteArray Pin
Victor Nijegorodov9-Jan-18 1:15
Victor Nijegorodov9-Jan-18 1:15 
AnswerRe: CString to CByteArray Pin
leon de boer9-Jan-18 2:26
leon de boer9-Jan-18 2:26 
GeneralRe: CString to CByteArray Pin
_Flaviu10-Jan-18 0:21
_Flaviu10-Jan-18 0:21 
QuestionMultiThread Question Pin
ForNow8-Jan-18 2:03
ForNow8-Jan-18 2:03 
AnswerRe: MultiThread Question Pin
Jochen Arndt8-Jan-18 2:28
professionalJochen Arndt8-Jan-18 2:28 
GeneralRe: MultiThread Question Pin
ForNow8-Jan-18 2:41
ForNow8-Jan-18 2:41 
GeneralRe: MultiThread Question Pin
Jochen Arndt8-Jan-18 3:00
professionalJochen Arndt8-Jan-18 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.