Skip to main content
edited body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

Every one has their own side of the holy war about where the '{' should be.

But one thing everybody agrees upon is that you must be consistent.
In your code you align the open and close (which I think is perfect) apart from when you use else

   }else{

Stay with the same style as the rest of your code

   }
   else
   {

If your 2 arrays are supposed to be identical then you should probably not have two different arrays. You should probably use a single array and use code to get the extra functionality. Otherwise you head into a maintenance problem where every addition to one array must be mirrored by an addition to the other array (and you must validate they are the same).

char * reservedFileNames[] = { "CON",  "PRN",  "AUX",  "NUL",
                               "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
                               "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };

   size_t  wordLen = strlen( reservedFileNames[i]);
   if( stricmp( reservedFileNames[i], name, wordLen) == 0 ) 
   {
       if (name[wordLen] == '\0')   // The strings are technically equal
       {    return 1;
       }
       if (name[wordLen] == '.')    // The string has a bad prefix.
       {    return s;1;
       }
   }

Every one has their own side of the holy war about where the '{' should be.

But one thing everybody agrees upon is that you must be consistent.
In your code you align the open and close (which I think is perfect) apart from when you use else

   }else{

Stay with the same style as the rest of your code

   }
   else
   {

If your 2 arrays are supposed to be identical then you should probably not have two different arrays. You should probably use a single array and use code to get the extra functionality. Otherwise you head into a maintenance problem where every addition to one array must be mirrored by an addition to the other array (and you must validate they are the same).

char * reservedFileNames[] = { "CON",  "PRN",  "AUX",  "NUL",
                               "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
                               "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };

   size_t  wordLen = strlen( reservedFileNames[i]);
   if( stricmp( reservedFileNames[i], name, wordLen) == 0 ) 
   {
       if (name[wordLen] == '\0')   // The strings are technically equal
       {    return 1;
       }
       if (name[wordLen] == '.')    // The string has a bad prefix.
       {    return s;
       }
   }

Every one has their own side of the holy war about where the '{' should be.

But one thing everybody agrees upon is that you must be consistent.
In your code you align the open and close (which I think is perfect) apart from when you use else

   }else{

Stay with the same style as the rest of your code

   }
   else
   {

If your 2 arrays are supposed to be identical then you should probably not have two different arrays. You should probably use a single array and use code to get the extra functionality. Otherwise you head into a maintenance problem where every addition to one array must be mirrored by an addition to the other array (and you must validate they are the same).

char * reservedFileNames[] = { "CON",  "PRN",  "AUX",  "NUL",
                               "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
                               "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };

   size_t  wordLen = strlen( reservedFileNames[i]);
   if( stricmp( reservedFileNames[i], name, wordLen) == 0 ) 
   {
       if (name[wordLen] == '\0')   // The strings are technically equal
       {    return 1;
       }
       if (name[wordLen] == '.')    // The string has a bad prefix.
       {    return 1;
       }
   }
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

Every one has their own side of the holy war about where the '{' should be.

But one thing everybody agrees upon is that you must be consistent.
In your code you align the open and close (which I think is perfect) apart from when you use else

   }else{

Stay with the same style as the rest of your code

   }
   else
   {

If your 2 arrays are supposed to be identical then you should probably not have two different arrays. You should probably use a single array and use code to get the extra functionality. Otherwise you head into a maintenance problem where every addition to one array must be mirrored by an addition to the other array (and you must validate they are the same).

char * reservedFileNames[] = { "CON",  "PRN",  "AUX",  "NUL",
                               "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
                               "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };

   size_t  wordLen = strlen( reservedFileNames[i]);
   if( stricmp( reservedFileNames[i], name, wordLen) == 0 ) 
   {
       if (name[wordLen] == '\0')   // The strings are technically equal
       {    return 1;
       }
       if (name[wordLen] == '.')    // The string has a bad prefix.
       {    return s;
       }
   }