TOPIC

Judge input is in DOS file format...

feodorv asked 2 years ago

I get eternal PE. Can't figure it out what's wrong. I've tried many variants of this code:

#include <stdio.h>
#include <string.h>

int mygets( char *s, int size)
{
  int len;
  if( fgets( s, size, stdin) == NULL ) return 0;
  if( (len = strlen( s )) > 0 && s[len-1] == '\n' ) s[--len] = '\0';
  return len;
}

/* ... */

int main( void )
{
  for(;;)
  {
    /* ... */  
    for(;;)
    {
      mygets( p[cnt], 16);
      if( *p[cnt] == '0' ) break;
      cnt++;
    }
    /* ... */
  }
  return 0;
}

PS:

The problem seems to be in the wrong file format of judge input. In C you should also check on ending '\r' (not only '\n') in the mygets function:

int mygets( char *s, int size)
{
  int len;
  if( fgets( s, size, stdin) == NULL ) return 0;
  len = strlen( s );
  if( len > 0 && s[len-1] == '\n' ) s[--len] = '\0';
  if( len > 0 && s[len-1] == '\r' ) s[--len] = '\0';
  return len;
}

"\r\n" is DOS line ending. This costs me many PE submissions :(

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.