Hi , I have this code for win xp

`char NotesDir[]  = "\\Program Files\\notesw32";
char Fname[]     = "C:\\Program Files\\notesw32\\notes.ini";
char Bakname[]   = "C:\\Program Files\\notesw32\\notesini.bak";`

But for win 7 , these files will be present in c:\Program Files (x86) folder. How do i make sure my code works for both xp and win 7? Can anyone help me with this? Can an environment variable be used? If so, How do i use it because i have never used it and am new to c programs. Thanks in Advance.

For paths like this, they shouldn't be hardcoded in the first place. Three options come to mind that are viable and reasonably easy to implement:

  1. Have the user type in the path.
  2. Store paths in a configuration file under the same folder as the executable. Then you can just use a relative path:

    char *NotesDir = strdup(argv[0]); /* Get the full path of the executable */
    char *Fname    = "notes.ini";
    char *Bakname  = "notesini.bak";
    
    /* Trim the executable name from the path */
    *strrchr(NotesDir, '\\') = '\0';
    
  3. Store the paths in the registry.

  4. Store the paths in an environment variable (see below).

I'd probably go with the configuration file for all but the simplest programs, where I'd use user input. The registry isn't really a recommended practice anymore, but it's still fairly commonly used.

Note that the sample code for option #2 makes two assumptions that you'll need to confirm or work around:

  1. strdup() is supported by the compiler's library.
  2. argv[0] gives you the full path of the executable.

Neither of these are guaranteed.

Can an environment variable be used?

Yes, you can use an environment variable. But either the variable needs to be created by your installer, or whoever installs the program needs to add it or the program won't work properly. Basically it's the same deal as a registry key, just in a different place.

Once the environment variable is there though, it's trivial to access using getenv(). The same can't be said about accessing registry keys, where you'll need to jump into the Win32 API.

Thanks much.. I have a environment variable called AZFFProgramFiles created by the admin. How do i make use of it in this program? Kindly advice. Thanks again.

Did you click on the link to a getenv() reference I provided in my previous reply? That's how you make use of environment variables, and it's a standard function so every compiler will support it.

Thanks . I did.. Suppose i use

char * pPath;
  pPath = getenv ("AZFFProgramFiles");//AZFFProgramFiles is the env variable by admin.

Will pPath take the value c:\programfiles or c:\programfiles x(86) depending on the os?
If yes, then how should i change

char Fname[]     = "C:\\Program Files\\notesw32\\notes.ini .

Appreciate your help

you may try this,
open the file, and check if it exist,
if its not exist,
open with win 7 file path format, and test again,
on of them should give you a file stream object,

char NotesDir[]  = "\\Program Files\\notesw32";
char Fname[]     = "C:\\Program Files\\notesw32\\notes.ini";
char Bakname[]   = "C:\\Program Files\\notesw32\\notesini.bak";
char NotesDirW7[]  = "\\Program Files (x86)\\notesw32";
char FnameW7[]     = "C:\\Program Files (x86)\\notesw32\\notes.ini";
char BaknameW7[]   = "C:\\Program Files (x86)\\notesw32\\notesini.bak";

ifstream file;
file.open(Fname, ifstream::in);
if (!ifile) {
  file.open(FnameW7, ifstream::in);
}

if(!file)
{
    handle File doesnt exist here
}

this should not be a fancy solution, but its a work around

also you may have a function that checks if directory c:\Program Files (x86) exist, then open the win 7 format

Will pPath take the value c:\programfiles or c:\programfiles x(86) depending on the os?

Um...yes. That's the whole point of using an environment variable to handle the non-constant path.

If yes, then how should i change

Those arrays should contain just the file name, and you can combine the two as needed:

char path[BUFSIZ];

strcpy(path, NotesDir); /* Push the full folder path */
strcat(path, "\\");     /* May not need this if NotesDir already includes it */
strcat(path, Fname);    /* Add the file name */

What you want is the win32 api function SHGetSpecialFolderPath(). This function is used to get path to several different operating system-dependent paths. For example if you want the path to "c:\Program Files(86)". The macro in the 3d parameter is defined in this list.

char path[MAX_PATH];
SHGetSpecialFolderPath(
    0,
    path, 
    CSIDL_PROGRAM_FILESX86, 
    FALSE ); 

For versions Vista or newer you may want to call SHGetKnownFolderPath() instead of the above.

64-bit version of MS-Windows always have both c:\Progrm Files and C:\Program Files(x86), so your program must know which one it wants. There is no win32 api function that will return the path to just one or the other of the folders.

Thanks All, But i have a problem when i try to read files from windows (x86) folder through my program ,it says "can't open file". Is win 7 probably preventing me to access that folder?

post the code that demonstrates the problem. I wouldn't think reading from any folder, just writing.

I am very sorry about the length of the program but i do not know who could help me at this moment :( This program when replaces program files x86 with just program files works fine in xp but when i test it in win 7 giving path as x86 ,it does not work. Please help :'(

 */
#define _CRT_SECURE_NO_DEPRECATE // added to disable deprecation. 
#define INCL_DOSFILEMGR
//CGI_CONV_OS2WIN_START
//Replaced os2.h with windows.h
//#include        <os2.h>
#include        <windows.h>
//CGI_CONV_OS2WIN_START

#include        <stdio.h>
#include        <string.h>
#include        <ctype.h>
#include        <io.h>
#include        <stdlib.h>
#include        <direct.h>
#include        <time.h>

//#define DEBUG

#define MAXSTRING        255

#ifndef TRUE
#define TRUE         1
#define FALSE        0
#endif
char tmp[MAXSTRING+1];                                 // file i/o work areas

//char (*pfun)(char *oldtext, char *newtext);    // pointer to format functions
void (*pfun)(char *oldtext, char *newtext);    // pointer to format functions

FILE *infile, *outfile, *errfile, *parmfile, *mapfile; // file pointers

int num_fields;                                           // number of fields

char NotesDir[]  = "\\Program Files (x86)\\notesw32";
char Fname[]     = "C:\\Program Files (x86)\\notesw32\\notes.ini";
char Bakname[]   = "C:\\Program Files (x86)\\notesw32\\notesini.bak";
char OutName[]   = "C:\\Program Files (x86)\\notesw32\\pwstemp.dat";         //VisChg
char ParmName[]  = "C:\\Program Files (x86)\\notesw32\\pwsparm.dat";

char MapName[]   = "C:\\PWS\\prd\\pwsmap.dat"; 
char ErrorFile[] = "C:\\PWS\\prd\\notesini.err";


int NotesDrv = 3;        // Drive C:
//--------------------------------------------------------------------------
//     Fields passed to Notes
//--------------------------------------------------------------------------

typedef struct FIELDSTRUC
{
        int  fieldnumber;
        char fieldname[30];
        char fieldfunction[30];
        char fieldtext[MAXSTRING+1];
} FIELDSTRUC;

FIELDSTRUC *Field;

//##########################################################################
//
//  Function Prototypes
//
//##########################################################################

void main(void);
void Process_Infile(void);
void Update_Outfile(void);
void Open_Infile(void);
void Open_Outfile(void);
void Open_Parm_File(void);
void Open_Map_File(void);
void quit( int error );
void message(char *s1,char *s2);
void FormatProducerNumber(char *oldtext, char *newtext);
void FormatProducerAddress(char *oldtext, char *newtext);
int  ProperCaseAddress(char *newcursor);
void FixComma(char *newcursor, char *newtext);
int  ProperCaseState(char *newcursor);
void FormatProducerName(char *oldtext, char *newtext);
void FormatNames(char *oldtext, char *newtext);
int  ProperCaseName(char *newcursor);
void FormatPolicyNumber(char *oldtext, char *newtext);
void Open_Error_File(void);
void FormatCov(char *oldtext, char *newtext);
void FormatAddress(char *oldtext, char *newtext);
void FormatState(char *oldtext, char *newtext);
void FormatZip(char *oldtext, char *newtext);
void FormatSentence(char *oldtext, char *newtext);
int  IsAllSpaces(char *newcursor);
int  FormatProper(char *newcursor);
void FormatConstruction(char *oldtext, char *newtext);
void NoFormat(char *oldtext, char *newtext);
void FormatResType(char *oldtext, char *newtext);

//##########################################################################
//
//
//
//##########################################################################

void main(void)
{
    char tokens[]=",";
    USHORT rc,datafield,i,j,k;
    char *token;                                                    //file I/O areas

    Open_Error_File();                     // so we can use it!
    _chdrive(NotesDrv);
    rc = _chdir(NotesDir);        //Visual C
    if(rc != 0)
          quit(8);              // This is the only error available
    //CGI_CONV_OS2WIN_END

//    if(rc == 2 || rc == 3)
//        quit(7);                        // No Notes Directory (Notes not installed!)
//    else if(rc != 0)
//               quit(8);              // Other error, couldn't change to Notes Directory

//--------------------------------------------------------------------------
// Read the mapfile and populate FIELD array with fieldnumber, fieldname
// and format function for each row
//--------------------------------------------------------------------------

       Open_Map_File();

       fgets(tmp, MAXSTRING, mapfile);          // Read the first lin in mapfile
       *(tmp + (strlen(tmp)-1)) = '\0';         // it has the number of fields

        //fprintf(errfile,"%s %s\n","ln1 MapFile",tmp);     //debug

       num_fields=atoi(tmp);

       // allocate memory for FIELD array
       if((Field=malloc((num_fields+1)*sizeof(FIELDSTRUC)))==NULL)                                                                                
       {
               quit(9);
       }
       // initialize mapfile record counter
       j=0;

       while(1)
       {

         fgets(tmp, MAXSTRING, mapfile);
          *(tmp + (strlen(tmp)-1)) = '\0';// input has \n in last position

        //fprintf(errfile,"%s %s\n","lnx MapFile",tmp);     //debug

         if (feof(mapfile) || (j == num_fields))
                break;

         // initialize token counter
         i=0;                                                          

         token=strtok(tmp,tokens);

         while(token != NULL && i<3)
         {
                i++;
                if (i==1)
                       Field[j].fieldnumber=atoi(token);// fieldnumber
                else if(i==2)
                       strncpy(Field[j].fieldname,token,30);// fieldname
                else
                       strncpy(Field[j].fieldfunction,token,30);// fieldtext

                token = strtok(NULL, tokens);
         };
         *(Field[j].fieldtext)='\0';// initialize fieldtext
         j++;
       };

       fclose(mapfile);

//--------------------------------------------------------------------------
// Read the parmfile and populate FIELD array with fieldtext depending
// upon the fieldnumber
//--------------------------------------------------------------------------

       Open_Parm_File();

       j=0;

       while(1)
       {

         fgets(tmp, MAXSTRING, parmfile);
          *(tmp + (strlen(tmp)-1)) = '\0';// input has \n in last position

        //fprintf(errfile,"%s %s\n","ParmFile",tmp);     //debug
         if (feof(parmfile) || j == num_fields)
                break;

         i=0;

         token=strtok(tmp,tokens);

         while(token != NULL && i<2)
         {
                i++;
                if (i==1)
                       k=atoi(token);                                  // k = fieldnumber
                else if(i==2)
                       strncpy(Field[k].fieldtext,token,MAXSTRING); //update row w/fieldnumber

                token = strtok(NULL, "\0");
         };
         j++;
       };

       fclose(parmfile);

//--------------------------------------------------------------------------
//Special processing to copy mail address into risk address if
//first line of risk address is blank
//--------------------------------------------------------------------------

#define INSD_MAIL_ADDR_1  8
#define INSD_MAIL_ADDR_2  9
#define INSD_MAIL_STATE  10 
#define INSD_MAIL_ZIP    11 
#define RISK_ADDR_1      12 
#define RISK_ADDR_STATE  13 
#define RISK_ADDR_ZIP   14
#define RISK_ADDR_2     20

       if (IsAllSpaces(Field[RISK_ADDR_1].fieldtext))
    {
        strcpy(Field[RISK_ADDR_1].fieldtext,       // copy INSD_MAIL_ADDR
              Field[INSD_MAIL_ADDR_1].fieldtext);
        strcpy(Field[RISK_ADDR_2].fieldtext,
                  Field[INSD_MAIL_ADDR_2].fieldtext);
               strcpy(Field[RISK_ADDR_ZIP].fieldtext,    // copy INSD_MAIL_ZIP
                  Field[INSD_MAIL_ZIP].fieldtext);
               strcpy(Field[RISK_ADDR_STATE].fieldtext,  // copy INSD_MAIL_STATE
                  Field[INSD_MAIL_STATE].fieldtext);
       }

//--------------------------------------------------------------------------
// Format the fields using the corresponding formatting function
//
//--------------------------------------------------------------------------

       for(datafield=0;datafield<num_fields;datafield++)
    {


       if(strcmp(Field[datafield].fieldfunction,"FormatProducerNumber")==0)
               pfun=FormatProducerNumber;
       else if(strcmp(Field[datafield].fieldfunction,"FormatPolicyNumber")==0)
               pfun=FormatPolicyNumber;
       else if(strcmp(Field[datafield].fieldfunction,"FormatCov")==0)
               pfun=FormatCov;
       else if(strcmp(Field[datafield].fieldfunction,"FormatProducerAddress")==0)
               pfun=FormatProducerAddress;
       else if(strcmp(Field[datafield].fieldfunction,"FormatAddress")==0)
               pfun=FormatAddress;
       else if(strcmp(Field[datafield].fieldfunction,"FormatState")==0)
               pfun=FormatState;
       else if(strcmp(Field[datafield].fieldfunction,"FormatZip")==0)
               pfun=FormatZip;
       else if(strcmp(Field[datafield].fieldfunction,"FormatConstruction")==0)
               pfun=FormatConstruction;
       else if(strcmp(Field[datafield].fieldfunction,"FormatProducerName")==0)
               pfun=FormatProducerName;
       else if(strcmp(Field[datafield].fieldfunction,"FormatNames")==0)
               pfun=FormatNames;
       else if(strcmp(Field[datafield].fieldfunction,"FormatSentence")==0)
               pfun=FormatSentence;
       else if(strcmp(Field[datafield].fieldfunction,"FormatResType")==0)
               pfun=FormatResType;
       else
               pfun=NoFormat;

       (*pfun)(Field[datafield].fieldtext, Field[datafield].fieldtext);
                                       // actual call to the formatting function





       }


    // Open the files

    Open_Infile();  // Notes.ini
    Open_Outfile(); // Temp work file


    // Copy infile to outfile, eliminating existing lines for our fields
    Process_Infile();

    // Add our new fields to outfile
    Update_Outfile();


    // Close files and move temporary file to original by renaming the
    //     original and renaming temporary.

    message("Finished ",Fname);

    fclose(infile);
    fclose(outfile);

    remove(Bakname); // notesini.bak

    if(rc = rename( Fname, Bakname)) // notes.ini -> notesini.bak
       quit(6);

//    rename( outpath, Fname);              // temp file -> notes.ini
    rename( OutName, Fname); //VisChg // temp file -> notes.ini

    //fclose(errfile);
    exit(0);
}



/***************************************************************************
 * Process_Infile
 *
 * Read the input file (NOTES.INI) and write it to the temporary outfile.
 * If any line contains one of the variables we are updating, do not
 * write it out.
 *
 **************************************************************************/

void Process_Infile(void)
{
    int found, datafield;

    while( 1 )
    {
     if( fgets( tmp, MAXSTRING, infile ) == NULL )
     {
            if( feof( infile ) )
                break;
            else
            {
//              fprintf(errfile,"feof(infile)\n");     //debug
                quit( 3 );
            }
     }
//    fprintf(errfile,"Notfeof(infile)\n");     //debug
     for(found = FALSE,datafield=0;datafield<num_fields;datafield++)
     {
         if(strncmp(Field[datafield].fieldname,tmp,strlen(Field[datafield].fieldname)) == 0)
          {
            found = TRUE;
            break;
          }
     }
     if(found);
     else
         //if( fputs( tmp, outfile ) != 0 )
         if( fputs( tmp, outfile ) == EOF )                  //visual c
         {
            //fprintf(errfile,"Notfound and something\n");     //debug
             quit( 3 );
         }
    }

}



/***************************************************************************
 * Update_Outfile
 *
 * Add the data lines for our variables to the temporary outfile.
 *
 **************************************************************************/

void Update_Outfile(void)     // write changes to bottom of temp file
{
    int datafield;

        for(datafield=0;datafield<num_fields;datafield++)
        fprintf(outfile,"%s=%s\n",Field[datafield].fieldname,Field[datafield].fieldtext);

}



//***************************************************************************

void Open_Infile(void)                     // notes.ini
{
    if ((infile = fopen(Fname,"r")) == NULL)
        quit(1);
}



//***************************************************************************


void Open_Outfile(void)     // Temporary file for making changes
{


//    mktemp( outpath );
//    outpath = tmpnam( NULL );   //visual C
//    if ((outfile = fopen(outpath,"w")) == NULL)
    if ((outfile = fopen(OutName,"w")) == NULL)
        quit(2);

}



void Open_Error_File(void)
{
    char DateTime[81], Time[12];

    // open error file

    if ((errfile = fopen(ErrorFile,"w")) == NULL)
        exit(5);

    // Put a Header with run date and time in the error file

    _strdate(DateTime);
    strcat(DateTime," ");
    _strtime(Time);
    strcat(DateTime,Time);

    message("NOTESINI.EXE\nUpdate policy data to Notes.ini",DateTime);
    message("","");                 // output a blank line
}


//*************************************************************************

void Open_Parm_File(void)            // pwsparm.dat
{
    if ((parmfile = fopen(ParmName,"r")) == NULL)
        quit(1);
}

//*************************************************************************

void Open_Map_File(void)                        // pwsmap.dat
{
       if ((mapfile = fopen(MapName,"r")) == NULL)
            quit(1);
}

//***************************************************************************

void FormatProducerNumber(char *oldtext, char *newtext)        // make it 99-999-999
{
       char buffer[MAXSTRING+1];
       char *oldcursor, *newcursor;

       if(strlen(oldtext) < 8)
        return;

       newcursor = buffer;
       oldcursor = oldtext;

       memcpy(newcursor, oldcursor,2);
       newcursor +=2;
       oldcursor +=2;
       *newcursor = '-';
       newcursor++;
       memcpy(newcursor, oldcursor,3);
       newcursor +=3;
       oldcursor +=3;
       *newcursor = '-';
       newcursor++;
       memcpy(newcursor, oldcursor,3);
       newcursor +=3;
       *newcursor = '\0';

       strcpy(newtext,buffer);
}

//--------------------------------------------------------------------------
// Add a space between prefix and number
//--------------------------------------------------------------------------

void FormatPolicyNumber(char *oldtext, char *newtext)
{

       char buffer[13];
       char *oldcursor, *newcursor;


       newcursor = buffer;
       oldcursor = oldtext;

       memcpy(newcursor, oldcursor,3);
       newcursor +=3;
       oldcursor +=3;

       *newcursor = ' ';
       newcursor++;

       strcpy(newcursor, oldcursor);

       strcpy(newtext,buffer);



}

//-------------------------------------------------------------------------
//  Make zero if blank 
//------------------------------------------------------------------------- 

void FormatCov(char *oldtext, char *newtext)
{
       char *buffer="0";

       int valid_amount = FALSE;

       char *oldcursor;

       oldcursor = oldtext;

       while(*oldcursor)
    {
               if(isdigit(*oldcursor))
        {
           valid_amount = TRUE;
           break;
        }
        else
                  oldcursor++;
    }

    if(!valid_amount)            
               strcpy(newtext,buffer);

}

//--------------------------------------------------------------------------

void FormatProducerAddress(char *oldtext, char *newtext)
{

       char *oldcursor, *newcursor;

       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       while(*newcursor)
    {

         if(*newcursor == ',')
          {
                  FixComma (newcursor, newtext);
                  newcursor++;
          }

         else if(*newcursor == ' ' || ispunct(*newcursor))
                         newcursor++;
           else
            {
                         newcursor+= (ProperCaseState(newcursor));

            }

     }
}

//--------------------------------------------------------------------------

void FixComma(char *newcursor, char *newtext)
{
    int inter;

       *newcursor = ' ';

       for (inter = 1;((newcursor - inter) > newtext)
                                  && (isspace (*(newcursor - inter))); inter++)
        {
            ;
        }

       if ((newcursor - inter) > newtext)
        {
            --inter;
            *(newcursor - inter) = ',';
        }
}

//--------------------------------------------------------------------------
// Make first character upper the rest lower unless two word state 
//-------------------------------------------------------------------------- 

int ProperCaseState(char *newcursor)
{
    int setuppercase;
    int charct = 0;
       int inter = 0;

    setuppercase = FALSE;

       if(*newcursor     == 'D' &&                     // two word state are uppercase
          *(newcursor+1) == 'C' &&
          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
          {
            charct = 2;
            setuppercase = TRUE;
          }

       else if(*newcursor      == 'N' &&
                  (*(newcursor+1) == 'C' || *(newcursor+1) == 'D'|| *(newcursor+1) == 'H' ||
                       *(newcursor+1) == 'J' || *(newcursor+1) == 'M'|| *(newcursor+1) == 'Y'   ) &&
                       (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
            {
             charct = 2;
             setuppercase = TRUE;
            }

       else if(*newcursor == 'R' &&
                       *(newcursor+1) == 'I' &&
                       (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
            {
             charct = 2;
             setuppercase = TRUE;
            }

       else if(*newcursor      == 'S' &&
               (*(newcursor+1) == 'C' || *(newcursor+1) == 'D') &&
          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
           {
            charct = 2;
            setuppercase = TRUE;
           }

       else if(*newcursor == 'W' &&
                       *(newcursor+1) == 'V' &&
                       (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
             {
                charct = 2;
              setuppercase = TRUE;
             }


     if (setuppercase)
         {
          for (inter = 0; inter < charct; ++inter)
            {

                        *(newcursor + inter) = (char)toupper(*(newcursor + inter));
            }
         }
     else
         {
                 *newcursor = (char)toupper(*newcursor);

                  for (inter = 1; isalnum(*(newcursor + inter) ); ++inter)
             {
                         *(newcursor + inter) = (char)tolower(*(newcursor + inter));
             }
          }


    return(inter);         // count of letters modified                 
}

//---------------------------------------------------------------------------
//  Format Street and City fields of Insured Mailing Address
//  Just proper case both fields  
//---------------------------------------------------------------------------

void FormatAddress(char *oldtext, char *newtext)
{            
       char *oldcursor, *newcursor;

       oldcursor = oldtext;
       newcursor = newtext;

       strcpy(newcursor, oldcursor);

       while (*newcursor)
    {
        if(*newcursor == ' ' || ispunct(*newcursor))
            newcursor++;
        else
            {
                newcursor+= (FormatProper(newcursor));
            }
    }                                        
}                                                                            

//---------------------------------------------------------------------------
//  Format State field of Insured Mailing Address
//  Special Logic  
//---------------------------------------------------------------------------

void FormatState(char *oldtext, char *newtext)
{     
       char *oldcursor, *newcursor;

       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       while (*newcursor)
    {
        if(*newcursor == ' ' || ispunct(*newcursor))
            newcursor++;
        else
            {
                newcursor+= (ProperCaseState(newcursor));
            }
    }                                                 
}                                                                             

//--------------------------------------------------------------------------

void FormatZip(char *oldtext, char *newtext)
{
    char buffer[MAXSTRING+1];
    char *newcursor, *oldcursor;

    oldcursor=oldtext;
    newcursor=buffer;

    if(strlen(oldcursor) < 6)
    return;

    memcpy(newcursor, oldcursor,5);
    newcursor +=5;
    oldcursor +=5;

    if(isdigit(*oldcursor)) // Is the 6th char a digit
    {
       *newcursor = '-';
       newcursor++;
       memcpy(newcursor, oldcursor,4);
       newcursor +=4;
       *newcursor = '\0';
    }
    else 
        *newcursor = '\0';

    strcpy(newtext,buffer);
}
//##########

//---------------------------------------------------------------------------
//  Format Sentence -- begin with Upper continue with lower until    
//  the first Alpha-numeric after the period.
//---------------------------------------------------------------------------

void FormatSentence(char *oldtext, char *newtext)
{            

       char *oldcursor, *newcursor;
       int beginsentence = 1;

       oldcursor = oldtext;
       newcursor = newtext;

       strcpy(newcursor, oldcursor);


       while (*newcursor)
       {
         if ( isalnum(*newcursor) )
         {
            if (beginsentence)
            {
               *newcursor = (char)toupper(*newcursor);
               beginsentence = 0;
            }
            else
            {
               *newcursor = (char)tolower(*newcursor);
            }
         }
         else
         {
            if(*newcursor == '.' )
            {
               beginsentence = 1;
            }
         }

       newcursor++;
       }                                        
}                                                                            


//##########
//--------------------------------------------------------------------------
// Checks Returns TRUE for all spaces in string
//--------------------------------------------------------------------------

int IsAllSpaces(char *newcursor)
{
    int inter = 0;

       while (*(newcursor+inter))
    {
       if(!isspace(*(newcursor+inter)))
           return(FALSE);
       inter++;
    }

    return (TRUE);
}

//-------------------------------------------------------------------------- 
//  Make first character upper the rest lower until no longer alphanumeric
//--------------------------------------------------------------------------  

int FormatProper(char *newcursor)
{ 
    int inter = 0;

       *newcursor = (char)toupper(*newcursor);
       for (inter = 1; isalnum(*(newcursor + inter)); ++inter)
    {
               *(newcursor + inter) = (char)tolower(*(newcursor + inter));
    }

    return (inter);
} 

//------------------------------------------------------------------------- 
// Do translation to format Construction   
//------------------------------------------------------------------------ 

void FormatConstruction(char *oldtext, char *newtext)
{ 
       char *oldcursor, *newcursor;

       char m_ver [81] = "M-VER";         // Brick Veneer or Masonry Veneer
    char msry  [81] = "MSRY";      // Brick or Masonry
    char fi_res[81] = "FI-RES";    // Fire Resistive
    char siding[81] = "SIDING";    // Alum or Plastic Siding

 // char stucco[81] = "STUCCO";    NOT NEEDED TRANSLATION THE SAME
 // char frame [81] = "FRAME";     NOT NEEDED TRANSLATION THE SAME

       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       if(strncmp(m_ver,newcursor,strlen(m_ver)) == 0)
               strcpy(newcursor,"Brick Veneer or Masonry Veneer");
       else if(strncmp(msry,newcursor,strlen(msry)) == 0)
               strcpy(newcursor,"Brick or Masonry");
       else if(strncmp(fi_res,newcursor,strlen(fi_res)) == 0)
               strcpy(newcursor,"Fire Resistive");
       else if(strncmp(siding,newcursor,strlen(siding)) == 0)
               strcpy(newcursor,"Alum or Plastic Siding");
// if none of the above don't modify--just set to proper case
    else
    {
          while (*newcursor)
       {
                if(*newcursor == ' ' || ispunct(*newcursor))
                       newcursor++;
         else
                       newcursor+= (FormatProper(newcursor));
       }
    }

} 


//------------------------------------------------------------------------- 
// Do translation to format Res Type       
//------------------------------------------------------------------------ 

void FormatResType(char *oldtext, char *newtext)
{ 


       char *oldcursor, *newcursor;

       char Primary [81] = "PRI"; 
    char Secondary  [81] = "SEC"; 
    char Seasonal[81] = "SEA";    


       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       if(strncmp("PRI",newcursor,3) == 0)
               strcpy(newcursor,"Primary");
       else if(strncmp("SEC",newcursor,3) == 0)
               strcpy(newcursor,"Secondary");
       else if(strncmp("SEA",newcursor,3) == 0)
               strcpy(newcursor,"Seasonal");

//     if(strncmp(Primary,newcursor,strlen(Primary)) == 0)
//             strcpy(newcursor,"Primary");
//     else if(strncmp(Secondary,newcursor,strlen(Secondary)) == 0)
//             strcpy(newcursor,"Secondary");
//     else if(strncmp(Seasonal,newcursor,strlen(Seasonal)) == 0)
//             strcpy(newcursor,"Seasonal");
///if none of the above don't modify--just set to proper case
//  else
//  {
//        while (*newcursor)
//    {
//              if(*newcursor == ' ' || ispunct(*newcursor))
//                     newcursor++;
//       else
//                     newcursor+= (FormatProper(newcursor));
//     }
//  }

} 

//---------------------------------------------------------------------------
//     Format Insured Name Field
//---------------------------------------------------------------------------

void FormatNames(char *oldtext, char *newtext)
{
       char *oldcursor, *newcursor;

       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       while(*newcursor)
    {

         if (*newcursor ==     '@')
         {
                       *newcursor = ' ';
                        newcursor++;
         } 
         else if(*newcursor == ' ' ||
                  ispunct(*newcursor) )
         {
                        newcursor++; 
         }
         else
         {
                       newcursor+= (ProperCaseName (newcursor));

         }

    }
}


//---------------------------------------------------------------------------
//     Format Producer Name Field
//---------------------------------------------------------------------------

void FormatProducerName(char *oldtext, char *newtext)
{
       char *oldcursor, *newcursor;
       int count;

       oldcursor=oldtext;
       newcursor=newtext;

       strcpy(newcursor, oldcursor);

       while(*newcursor)
    {
         if (*newcursor ==     '@')
         {
                       *newcursor = ' ';
                        newcursor++;
         } 
         else if(*newcursor == ' ' ||
                  ispunct(*newcursor) )
         {
                        newcursor++;
         }
         else
         {
                       if ( count=ProperCaseName(newcursor) ) 
                       {
                               newcursor+=count;
                       }        
                       else
                       {  
                                newcursor+=ProperCaseState(newcursor);
                       }        
         }

    }
}


//--------------------------------------------------------------------------
//  Determine and implement Case Settings for NAMES 
//  Does proper case and also allows for articles, conjunctions etc. 
//  Does special handling of Mc and other special situations  
//-------------------------------------------------------------------------- 
int ProperCaseName(char *newcursor)
{
    int setlowercase;
    int setuppercase;
    int charct = 0;
    int inter = 0;
    setlowercase = FALSE;
    setuppercase = FALSE;

       if(*newcursor     == 'A' &&      // conjuctions & prepositions lowercase
          *(newcursor+1) == 'N' &&
          *(newcursor+2) == 'D' &&
          (isspace(*(newcursor+3)) || *(newcursor+3) == '\0') )
           {
            charct = 3;
            setlowercase = TRUE;
           }

       else if(*newcursor == 'O' &&
          (*(newcursor+1) == 'R' || *(newcursor+1) == 'F') &&
          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
           {
            charct = 2;
            setlowercase = TRUE;
           }

       else if(*newcursor == 'T' &&
          *(newcursor+1)  == 'O' &&
          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
           {
            charct = 2;
            setlowercase = TRUE;
           }

       else if(*newcursor == 'B' &&
          *(newcursor+1)  == 'Y' &&
          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
           {
            charct = 2;
            setlowercase = TRUE;
            }

       else if(*newcursor == 'F' &&
                *(newcursor+1) == 'O' &&
                *(newcursor+2) == 'R' &&
          (isspace(*(newcursor+3)) || *(newcursor+3) == '\0') )
           {
            charct = 3;
            setlowercase = TRUE;
           }

       else if(*newcursor == 'I' &&                       // II III IV & V uppercase
                *(newcursor+1) == 'I' &&
                *(newcursor+2) == 'I' &&
          (isspace(*(newcursor+3)) || *(newcursor+3) == '\0') )
           {
            charct = 3;
            setuppercase = TRUE;
           }

       else if(*newcursor == 'I' &&
          (*(newcursor+1) == 'I' ||  *(newcursor+1) == 'V') &&

          (isspace(*(newcursor+2)) || *(newcursor+2) == '\0') )
           {
            charct = 2;
            setuppercase = TRUE;
           }


//
// Test for Case Determination and implement accordingly 
//

    if (setlowercase)
         {
          for (inter = 0; inter < charct; ++inter)
            {
                        *(newcursor + inter) = (char)tolower(*(newcursor + inter));
            }
         }

    else if (setuppercase)
         {
          for (inter = 0; inter < charct; ++inter)
            {
                        *(newcursor + inter) = (char)toupper(*(newcursor + inter));
            }
         }
         else
            {
                        *newcursor = (char)toupper (*newcursor);

                        for (inter = 1; isalnum(*(newcursor + inter)); ++inter)
               {
                               *(newcursor + inter) = (char)tolower(*(newcursor + inter));
               }

             if((inter > 3) &&                        // McSomething
                         ( *newcursor == 'M' &&
                               *(newcursor+1) == 'c'))
             {
                          *(newcursor+2) = (char)toupper(*(newcursor+2));
             }
                       }

       return(inter);          //count of letters modified

}

//--------------------------------------------------------------------------
// This function does nothing
//--------------------------------------------------------------------------

void NoFormat(char *oldtext, char *newtext)                                                                                               
{ 


       char *oldcursor, *newcursor;

       oldcursor=oldtext;
       newcursor=newtext;

       return;
}

//---------------------------------------------------------------------------
// Handles errors 
//------------------------------------------------------------------------- 

void quit( int error )
{
    switch( error )
    {
        case 1:
            message( "Can't open input file", Fname );
            break;
        case 2:
//            message( "Can't open output file", outpath);
            message( "Can't open output file", OutName);     //VisChg
            _fcloseall();
            break;
        case 3:
            message( "Error processing file", Fname);
            _fcloseall();
//            remove( outpath );
            remove( OutName );                              //VisChg
            break;
        case 4:
            message( "Can't open input file", ParmName);
            _fcloseall();
            break;
        case 5:
            message( "Invalid program invocation", "Too few policy data fields" );
            break;
        case 6:
            message( "Can't backup notes.ini", "Update aborted!");
            _fcloseall();
            remove( OutName );                              //VisChg
 //           remove( outpath );
            break;
        case 7:
            message( "*** Lotus Notes Not Installed", "" );
            break;
        case 8:
            //CGI_CONV_OS2WIN_START
            //message( "*** Unable to change to Lotus Notes Directory", "e:\\data\\notes" );
            message( "*** Unable to change to Lotus Notes Directory", "C:\\Program Files\\notesw32" );
            //CGI_CONV_OS2WIN_START
                       break;
               case 9:
                       message( "*** Unable to allocate memory", "" );
                       break;
    }
    exit( -1 );
}



//-------------------------------------------------------------------------
// Put a message to the error log     
//-------------------------------------------------------------------------- 

void message(s1,s2)                
char    *s1, *s2;
{
    fprintf(errfile,"%s %s\n",s1,s2);
}

//***************************************************************************
//  END OF PROGRAM
//***************************************************************************

what compiler are you using? It won't compile with VC++ 2012 because some of the constructs are just too ancient, such as this one

void message(s1,s2)                
char    *s1, *s2;
{
    fprintf(errfile,"%s %s\n",s1,s2);
}

am using vc++ 2005.. the error file log says "Can't Open Input file C:\Programfiles (X86)\NotesW32\Notes.ini"

Your compiler has a great debugger. Single step through the program so that you can easily see what's going on. My guess is that the input file doesn't exist. Also check permissions on the folder to see if you have read permissions.

Yeah , i manually typed the error sorry... This is what the error file log says:
NOTESINI.EXE
Update policy data to Notes.ini 12/10/12 06:08:06

Can't open input file C:\Program Files (x86)\notesw32\notes.ini

I changed my response above. I got the same error because the file does not exist.

C:\Programfiles (X86)\NotesW32\Notes.ini , This file is present but like you said i think i don't have access permission. If i get admin priveleges, will the program work?

Are you logged into the computer with Admin permission? You can check the permissions with Windows File Explorer. Post your Notes.ini file so I have something to work with.

This is my notes.ini file . My program should append some data to the end of this file. I manually tried to modify this file and i was able to do it.

[Notes]
    KitType=1
    Directory=C:\Data\NotesW32
    InstallType=6
    InstallMode=1
    NotesProgram=C:\Program Files (x86)\NotesW32\
    FaultRecovery_Build=Release 8.5.3
    Timezone=8
    DSTLAW=3,2,1,11,1,1
    USING_LOCAL_SHARED_MEM=1
    LOCAL_SHARED_MEM_SESSION_ID=0
    ExtMgr_Addins=NLNVP.DLL
    FileDlgDirectory=C:\Users\Default\Documents
    SU_IN_PROGRESS=0
    SU_NEXT_UPDATE=11/22/2012 09:50:50 PM
    SU_DELAY_DAYS=0
    SU_FILE_CLEANUP=C:\Users\p76ibm3\AppData\Roaming\smkits
    SUT_NEXT_UPDATE=11/23/2012 10:50:50 PM
    FontIncrease=0
    StandardWorkspace=1
    DST=1
    MailType=0
    $$HasLANPort=1
    $IEVersionMajor=6
    $IEVersionMinor=1
    WWWDSP_SYNC_BROWSERCACHE=1
    WWWDSP_PREFETCH_OBJECT=1
    EnableJavaApplets=1
    EnablePlugins=1
    Preferences=3185
    PrefAPIVer=197
    AltNameLanguage=en
    ContentLanguage=en-US
    WeekStart=1
    ViewWeekStart=2
    NavWeekStart=1
    XLATE_CSID=52
    SPELL_LANG=1033
    SPELL_PREFERENCES=0
    Region=en-US
    DatePickerDirection=0
    EnableBiDiNotes=0
    GlobalTextDir=1
    ScriptRTFVisualCaretMovement=0
    Passthru_LogLevel=0
    Console_LogLevel=2
    VIEWIMP1=Lotus 1-2-3,0,_IWKSV,,.123,.WK1,.WK3,.WK4,.WKS,.WR1,.WRK,,4,
    VIEWIMP2=Structured Text,0,_ISTR,,.CGN,.LTR,.STR,._UNKNOWN,,,1,
    VIEWIMP3=Tabular Text,0,_ITAB,,.PRN,.RPT,.TAB,.TXT,.TSV,,1,
    VIEWIMP4=vCard,0,_IVCRD,,.VCF,,1,
    VIEWIMP5=Calendar File (.ics),0,_IICAL,,.ICS,.VCS,,1,
    VIEWIMP6=Comma Separated Value,0,_ICSV,,.CSV,,1,
    VIEWEXP1=Comma Separated Value,0,_XCSV,,.CSV,,1,
    VIEWEXP2=Lotus 1-2-3,0,_XWKS,,.123,.WK1,.WK3,.WK4,.WKS,.WR1,.WRK,,4,
    VIEWEXP3=Structured Text,0,_XSTR,,.CGN,.LTR,.STR,._UNKNOWN,,1,
    VIEWEXP4=Tabular Text,1,_XTAB,,.CGN,.LTR,.RPT,.TAB,.TXT,,1,
    VIEWEXP5=vCard,0,_XVCRD3,,.VCF,,1,
    VIEWEXP6=Calendar File (.ics),0,_XICAL,,.ICS,,1,
    EDITIMP1=ASCII Text,0,_ITEXT,,.C,.H,.PRN,.RIP,.TXT,,1,
    EDITIMP2=Binary with Text,0,_ISTRNGS,,.*,,1,
    EDITIMP3=BMP Image,0,_IBMP,,.BMP,,18,
    EDITIMP4=CGM Image,0,_IFL,,.CGM,.GMF,,8,
    EDITIMP5=GIF Image,0,_IGIF,,.GIF,,18,
    EDITIMP6=HTML File,0,_IHTML,,.HTM,.HTML,,1,
    EDITIMP7=JPEG Image,0,_IJPEG,,.JPG,.JPEG,,18,
    EDITIMP8=Lotus 1-2-3,0,_IW4W,_IWKSE,.123,.WK1,.WK3,.WK4,.WKS,.WR1,.WRK,,4,
    EDITIMP9=Lotus PIC,0,_IPIC,,.PIC,,8,
    EDITIMP10=Lotus Word Pro,0,_IW4W,,.LWP,,2,
    EDITIMP11=Microsoft Excel,0,_IW4W,,.XLS,,4,
    EDITIMP12=Microsoft RTF,0,_IRTF,_IW4W,.RTF,,2,
    EDITIMP13=Microsoft Word,0,_IW4W,,.DOC,,2,
    EDITIMP14=Network Portable Graphics,0,_IW4W,,.PNG,,18,
    EDITIMP15=PCX Image,0,_IPCX,,.PCX,,18,
    EDITIMP16=TIFF 5.0 Image,0,_ITIFF,,.TIF,,18,
    EDITIMP17=WordPerfect,0,_IW4W,,.WPD,.WPT,,2,
    EDITIMP18=Unsupported File as Text,0,_ITEXT,,.*,._UNKNOWN,,1,
    EDITIMP19=Symphony Document (.ODT),0,_IW4W,,.ODT,,2,
    EDITIMP20=Symphony Spreadsheet (.ODS),0,_IW4W,,.ODS,,2,
    EDITIMP21=Symphony Presentation (.ODP),0,_IW4W,,.ODP,,2,
    EDITIMP22=Microsoft Word 2007,0,_IW4W,,.DOCX,,2,
    EDITIMP23=Microsoft Excel 2007,0,_IW4W,,.XLSX,,2,
    EDITEXP1=ASCII Text,2,_XTEXT,,.C,.H,.PRN,.RIP,.TXT,._UNKNOWN,,1,
    EDITEXP2=CGM Image,2,_XCGM,,.CGM,.GMF,,8,
    EDITEXP3=Microsoft RTF,2,_XRTF,,.DOC,.RTF,,4,
    EDITEXP4=TIFF 5.0 Image,2,_XTIFF,,.TIF,,18,
    EDITEXP5=vCard,0,_XVCRD3,,.VCF,,1,
    DDETimeout=10
    NAMEDSTYLE0=030042617369630000000000000000000000000000000000000000000000000000000000000001010100000A0000000000000100A0050A0000006400A0050A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009404000000000000
    NAMEDSTYLE0_FACE=Default Sans Serif
    NAMEDSTYLE1=030042756C6C657400000000000000000000000000000000000000000000000000000000000001010100000A000000000000000008070A000000640008070A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049404000000000000
    NAMEDSTYLE1_FACE=Default Sans Serif
    NAMEDSTYLE2=0300486561646C696E6500000000000000000000000000000000000000000000000000000000010101010B0C0000000000000100A0050A0000006400A0050A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009404000000000000
    NAMEDSTYLE2_FACE=Default Sans Serif
    DefaultMailTemplate=mail85.ntf
    KeyFileName=user.id
    CertificateExpChecked=user.id 12/10/2012
    KeyFileName_Owner=CN=Harish Nagaraj/O=Harish Nagaraj
    SPELL_IMPORTED_UD=1
    NOTES_USER_POLICIES_SETUP_LEVEL=1
    PoliciesLocalViewModTime=88257ABF:0025A717
    TCPIP=TCP, 0, 15, 0
    LAN0=NETBIOS, 0, 15, 0
    Ports=TCPIP
    DisabledPorts=LAN0
    TemplateSetup=850300
    VIEW_ICONPOPUP=1
    Setup=850300
    Location=Online,9DA,CN=Harish Nagaraj/O=Harish Nagaraj
    IsUserUpgrade=0
    LastProvisioningVersion=1350686493279
    PhoneLog=2
    Log=log.nsf, 1, 0, 7, 40000
    ECLSetup=3
    MailUpgradeCheckTime=2B58A1
    $headlineClientId=D5412E39:89EF7024-88257ABF:002B58C9
    $USE_WCT_IM=1
    $USE_ST_IM=0
    SYMPHONY_INSTALLED=0
    IDVAULT_COUNT1=0
    IDVAULT_STAMP1=11/22/2012 11:54:08 PM
    LastHistoryPruneTime=12/07/2012 07:50:57 AM
    WindowSizeBrowse=348 186 499 287
    ExitNotesPrompt=0
    DESKWINDOWSIZE=0 0 961 571
    WINDOWSIZEWIN=25 14 1230 670
    MAXIMIZED=0
    URLAddress1=notes:///ClientBookmark?OpenWorkspace

The error message is incorrect, program is unable to open pwsparam.dat not notes.ini

Thanks, I corrected that by placing the file manually there but i have another problem

void FormatPolicyNumber(char *oldtext, char *newtext) {

   char buffer[13]="";
   char *oldcursor;
   char *newcursor;


   newcursor = buffer;
   oldcursor = oldtext;

   memcpy(newcursor, oldcursor,3);
   newcursor +=3;
   oldcursor +=3;

   *newcursor = ' ';
   newcursor++;

   strcpy(newcursor, oldcursor);

   strcpy(newtext,buffer);
   }

Unhandled exception at 0x777415de in PWSPLINI.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.

  • buffer 0x0018ff04 "ÌÌÌÌ" char [13]
  • newcursor 0xcccccccc char *
  • newtext 0x005e1a80 "ˆ^" char *
  • oldcursor 0xcccccccc char *

I am using vs 2005 ,please help

The function is called this way
if(strcmp(Field[datafield].fieldfunction,"FormatPolicyNumber")==0) pfun=FormatPolicyNumber;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.