Anyone see anything really wrong with this? Its purpose is to get the name of the executed file strip off all the junk before and any extentions after it and then append .cfg to the end.

IE: The exe name is "bob.exe" and it is in "/home/me/blah/" the argv[0] value might be "/home/me/blah/bob.exe" which the program converts into "bob.cfg".

I ran it on Linux and Windows using gcc and Dev-C++ respectfully and it works on both.

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

void getcfgname (char *, char *, char *);

int main (int argc, char *argv[])
{
  int count;
  char *p_first, *p_end, filename[30];

  if ( (p_first = strrchr (argv[0], '/')) == NULL) /* If Null not unix */
  {
    if ( (p_first = strrchr (argv[0], '\\')) == NULL) /* If Null not windows */
      p_first = argv[0]; /* so set it to the first */
    else
      p_first++;
  }
  else
    p_first++;

  if ( (p_end = strchr ( p_first, '.')) == NULL) /* No . after the first */
    p_end = p_first + strlen(p_first);

  getcfgname( p_first, p_end, filename);

  printf("%s\n", filename);

  return 0;
}

void getcfgname ( char *fi, char *en, char *name)
{
  int count=0;
  char *p;

  for (p=fi; p!=en; p++, count++)
  {
    name[count] = *p;
  }
  name[count]='\0';
  strcat (name, ".cfg");
}