Novice needs help

This is a discussion on Novice needs help within the C++ Programming forums, part of the General Programming Boards category; Hello, I am trying to run a set of codes written by sb else. here is what I did to ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    7

    Novice needs help

    Hello,

    I am trying to run a set of codes written by sb else. here is what I did to run them in VC++6:

    1- created a new project "Win 32 console application" as "a simple application" so StdAfx.h and StdAfx.cpp are added to my project.
    2- added the .C files and the .h files by sb else to my project.
    3- I get "fatal error C1010: unexpected end of file while looking for precompiled header directive" for all the c files that I have.

    PS: if i create an Empty application at the beginning, the error is "Cannot open include file: 'strstream.h': No such file or directory" and "Cannot open include file: 'nan.h': No such file or directory".

    Some body could help please?

    Thanks,
    Nick

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    - create simple console project
    - DELETE all the stdafx rubbish
    - In the project settings compiler->preprocessor, turn OFF "use precompiled headers"
    - store your code in the project, compile and enjoy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    7
    In this case I get following error:
    fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    > unexpected end of file while looking for precompiled header directive
    You didn't turn it off then.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    7
    now it is off but it gives me tons of syntax error on the codes like:

    c:\files\posdoc\ladtools\basics\basic.h(33) : error C2143: syntax error : missing '{' before '<'
    c:\files\posdoc\ladtools\basics\basic.h(33) : error C2059: syntax error : '<'
    c:\files\posdoc\ladtools\basics\basic.h(65) : error C2054: expected '(' to follow 'inline'
    c:\files\posdoc\ladtools\basics\basic.h(66) : error C2085: 'IsBoolean' : not in formal parameter list
    c:\files\posdoc\ladtools\basics\basic.h(66) : error C2143: syntax error : missing ';' before '{'
    c:\files\posdoc\ladtools\basics\basic.h(71) : error C2054: expected '(' to follow 'inline'
    c:\files\posdoc\ladtools\basics\basic.h(72) : error C2085: 'IsExtBoolean' : not in formal parameter list
    c:\files\posdoc\ladtools\basics\basic.h(72) : error C2143: syntax error : missing ';' before '{'
    c:\files\posdoc\ladtools\basics\basic.h(78) : error C2143: syntax error : missing ')' before '&'
    c:\files\posdoc\ladtools\basics\basic.h(78) : error C2143: syntax error : missing '{' before '&'


    but i know the codes are ok!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    Quote Originally Posted by ghaasemi
    but i know the codes are ok!
    Just show the code anyway.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    7
    here is the code:

    Code:
    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    
    
    #include "../Basics/basic.h"
    
    
    #define Debug true
    
    
    
    static uint MaxVarNum = 0;
    static char** Variable = NULL;
    
    
    
    void SubstituteVariables (char* S)
    {
      if (StrIsEmpty (S))
        return;
      
    
      ForEver
        {      
          char* VarStart = strstr (S, "(*");
          if (VarStart == NULL)
    	break;
          
          for (uint i = 2; VarStart [i] != 0 && VarStart [i] != ')'; i++);
          assert (VarStart [i] != 0);
    
          uint VarNum;      
          if (sscanf (& VarStart [2], "%u", & VarNum) != 1)
    	RunError;
          assert (VarNum > 0 && VarNum <= MaxVarNum);      
          
          StrReplace (VarStart, i + 1, Variable [VarNum - 1]);      
        }
    }
    
    
    
    boolean Execute (const char* InFName,
    		 uint& LineNum)
    {
      FILE* FIn = fopen (InFName, "r");
      if (FIn == NULL)
        {
          printf ("Cannot open file \"%s\"\n", InFName);
          exit (1);
        }
      SkipLines (FIn, LineNum);
        
      
      // Preparing parameter file
      printf ("\n");
      const uint SLen = 1024;  
      char Program [SLen] = "";
      char ParamFName [SLen];
      FILE* FOut = NULL;
      char S [SLen];
      while (ReadLine (FIn, S, SLen))
        {
          LineNum++;
    
    
          StrTrimTrailing (S);      
          SubstituteVariables (S);
    
    
          if (StrIsEmpty (S))
    	if (FOut == NULL)
    	  /*Nothing*/; 
    	else
    	  break;
    
          else if (S [0] == '*')  // Comment
    	/*Nothing*/;
          
          else if (S [0] == ':' ||
    	       S [0] == '!')
    	{
    	  if (FOut != NULL)
    	    {
    	      printf ("Line %u: %s\n", LineNum, S);
    	      printf ("Blank line should be inserted\n");
    	      exit (1);
    	    }
    
    	  boolean BuiltinCommand = (S [0] == '!');
    	  
    	  S [0] = ' ';
    	  StrTrimLeading (S);
    
    	  if (! BuiltinCommand)
    	    strcpy (Program, "/rutcor/u1/brover/c/LAD/");
    	  strcat (Program, S);
    	    
    	  tmpnam (ParamFName);
    	  //strcat (ParamFName, "-"); ??
    	  //strcat (ParamFName, S);   ??
    	  strcat (ParamFName, ".in");
    	  
    	  FOut = fopen (ParamFName, "w");
    	  assert (FOut != NULL);	    
    	}      
    
          else
    	{
    	  if (FOut == NULL)
    	    {
    	      printf ("Line %u: %s\n", LineNum, S);
    	      printf ("\": <File name>\" should be specified\n");
    	      exit (1);
    	    }
    	  
    	  uint i = strlen (S); 
    	  while (S [i] != ' ' && S [i] != ':') 
    	    i--;
    	  fprintf (FOut, "%s\n", & S [i + 1]);
    	  printf ("%s\n", S); 
    	}      
        }
    
      
      fclose (FIn);  
    
      if (FOut == NULL)
        return false;
      boolean ParamExist = ! FileEmpty (FOut);
      fclose (FOut);
    
    
      // Execution
      if (ParamExist)
        {
          strcat (Program, " < ");
          strcat (Program, ParamFName);
    	  
          //strcat (Program, " > /dev/null");	  
        }
      printf ("\n%s\n", Program);  
      int Result = system (Program);  
    
    
      // Delete ParamFName
      remove (ParamFName); 
    
    
      return Result == 0;
    }
    
      
    
    void Instruction ()
    {
    
      printf ("Logical Analysis of Data: 3 steps in one run\n");
      printf ("Usage: LAD <Parameter file> [<Var1> <Var2> ...]\n");
      printf ("<VarK>, K >=1,  substitues expression \"(*K)\" in the parameter file\n"); 
      printf ("Example of parameter file is \"LAD.in\"\n");
    
      exit (2);  
    }
    
    
    
    int main (int argc, char *argv[])
    {    
      if (argc < 2)
        Instruction ();
    
      MaxVarNum = argc - 2;
      Variable = new char* [MaxVarNum];
      for (uint i = 0; i < MaxVarNum; i++)
        Variable [i] = argv [i + 2];
    
      uint LineNum = 0;
      while (Execute (argv [1], LineNum));  
    
      delete Variable;
      
      
      return 0;
    }
    Last edited by Salem; 05-30-2009 at 07:17 AM. Reason: Added code tags, learn to use them yourself

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    7
    And the basic.h



    Code:
    // basic.h
    // Purpose:  Basic operations
    // Language: C++
    
    
    
    #ifndef basic_h
    #define basic_h 
    
    
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <float.h>
    
    
    
    
    /////////////////////////////////// General ////////////////////////////////
    
    #define  ForEver   for (;;)
    #define  For(i,N)  for (uint i = 0; i < (N); i++)    
    #define  Case      break; case
    #define  Default   break; default
    #define  tcT 	   template <class T>
    
    typedef  unsigned char     byte;
    typedef  unsigned int      uint;
    typedef  long int          lint;
    typedef  long unsigned int luint;
    typedef  long double       ldouble;
    
    tcT void Exchange (T &X,
    		   T &Y);
      // If (& X == & Y) then return
    
    
    
    
    ////////////////////////////////// Debugging ///////////////////////////////
    
    #define  assert(Cond)                                     \
      if (Debug)                                              \
        {                                                     \
          if (! (Cond))                                       \
    	{                                                 \
    	  printf ("\n\"%s\", line %d:\nCheck fail: %s\n", \
                      __FILE__, __LINE__, #Cond);             \
    	  exit (1);                                       \
    	}                                                 \
        }
    
    #define RunError assert(false)
    
    
    
    
    /////////////////////////////////// boolean /////////////////////////////////
    
    typedef  signed char    boolean;
      // "signed" - for downward cycles
    enum     {false, true, BooleanDontKnow};
    extern   const char  Bool2Char [3/*boolean*/];
    
    inline boolean IsBoolean (int N)
      {
        return (N == false || 
    	    N == true);  
      }
    
    inline boolean IsExtBoolean (int N)
      {
        return (N == false || 
    	    N == true  ||
    	    N == BooleanDontKnow);  
      }
    
    void Toggle (boolean &B);
    
    inline int  Boolean2Sign (boolean B)
      { return B ? 1 : -1; }  
     
    #define  ForBoolean(B)      for (boolean B = false; B <= true;  B++)
    #define  ForBooleanDown(B)  for (boolean B = true;  B >= false; B--)
      
    
    
    
    /////////////////////////////////// Array //////////////////////////////////
    
    tcT T* ArrayInsert (uint Index, 
    		    T*   &Data, 
    		    uint &DataSize);
      // Insert 1 new element into Data at position Index
      // Return: pointer to the new element
      // DataSize++
      // Data != NULL
    
    tcT T* ArrayAppend (T*   &Data,
    		    uint &DataSize);
      // Invokes: ArrayInsert
    
    tcT void ArrayAugment (T*   &Data,
    		       uint &DataSize,
    		       uint Inc);
      // DataSize += Inc
      // Data != NULL
    
    tcT void ArrayDelete (uint Index,
    		      T*   &Data,
    		      uint &DataSize);
      // DataSize--
      // Data != NULL
    
    tcT void ArrayReduce (T*   &Data,
    		      uint &DataSize,
    		      uint Dec);
      // DataSize -= Dec
      // Data != NULL
    
    
    
    
    //////////////////////////////////// ROOT ///////////////////////////////////
    
    class ROOT
    {
    public:  
      uint ErrorNum;  
        // 0 - no error
        // 1 - out of memory
    
      ROOT ()  { ErrorNum = 0; };
      virtual ~ROOT ()  {};
    };
    
    
    
    
    //////////////////////////////////// NAMED /////////////////////////////////
    
    class NAMED: public ROOT
    {
    typedef ROOT inherited;
    
    public:  
      char* Name;
      
      NAMED  (const char* initName);
      ~NAMED ();
    };
    
    
    
    
    /////////////////////////////////// String /////////////////////////////////
    
    char*    StrNew (const char* S);
    
    char*    StrRename (char* &S,
    		    const char* NewS);
    
    char*    StrEnd (char* S);
    
    boolean  StrIsEmpty (const char* S);
    
    boolean  StrIsBlank (const char* S);
      // true iff all characters in S are spaces
    
    char*    StrChar (char  C,
    		  uint  Len,
    		  char* S);
      // Len - effective length of S
    
    char*    StrBlank (uint  Len,
    		   char* S);
      // Len - effective length of S
    
    char*    Long2Str (lint  X,
    		   char* S);
    
    boolean  String2Boolean (const char *S);
      // Return: "1" - true, "0" - false, else BooleanDontKnow
    
    char*    StrTrimLeading (char* S);
      // Delete leading blanks
    
    char*    StrTrimTrailing (char* S);
      // Delete trailing blanks
    
    char*    StrTrim (char* S);
      // Delete leading and trailing blanks
    
    boolean  StrIsLeft (const char* S,
    		    const char* Left);
    
    char*    StrDeleteBlanks (char* S);
    
    void     StrReplace (char* Target,
    		     uint Len,
    		     const char* Source);
      // Replace Len first characters of Target by Source
    
    char*    StrVarIndex (const char* VarName,
    		      uint Index,
    		      uint Len,
    		      char* Res);
      // Return: VarName + Index
    
    
    
    
    ////////////////////////////////////// I/O //////////////////////////////////
    
    void PrintLn ();
    
    void PrintLines (uint LineNum);
    
    void SkipLine (FILE* F);
    
    void SkipLines (FILE* F,
    		uint LineNum);
    
    char SkipBlanks (FILE* F);
      // Skips blanks, tabs
      // Return: first non-blank character
      // Current point is before the character returned
    
    boolean ReadLine (FILE* F, 
    		  char* S, 
    		  uint  Len);
      // false iff EOF
     
    boolean ReadDouble (FILE* F, 
    		    double &N);
      // Return: FALSE if '\n'
      // Output: N 
      // If '\n' then SkipLine (F)
    
    boolean ReadFloat (FILE* F, 
    		   float &N);
      // Invokes: ReadDouble
    
    boolean ReadInt (FILE* F, 
    		 int &N);
      // Invokes: ReadDouble 
    
    boolean ReadUint (FILE* F, 
    		  uint &N);
      // Invokes: ReadDouble 
    
    boolean ReadString (FILE* F,
    		    char* S,
    		    uint Len);
      // String is delimited by blanks (or \n, \t, \r)
      // Return: true if ! StrEmpty (S)
    
    boolean FileExists (const char* FName);
    
    lint FileSize (FILE* F);
    
    boolean FileEmpty (FILE* F);
    
    
    
    
    ///////////////////////////////// Mathematics ///////////////////////////////
    
    extern const int  MININT;
    extern const uint MAXUINT;
    
    
    boolean Between (lint N,
    		 lint L, 
    		 lint U);
      // true if L <= N < U 
    
    boolean BetweenEqual (lint N,
    		      lint L, 
    		      lint U);
      // true if L <= N <= U 
    
    lint nint (double X);
      // Missing in math.h -??
    
    lint lceil (double f);
    
    lint lfloor (double f);
    
    tcT inline T absolute (const T a) 
      { return ( (a>0) ? a : -a ); }
      // Requires: T is integer class
    
    tcT inline T minimum (const T a, 
    		      const T b)
      { return ( (a<b) ? a : b ); }
    
    tcT inline T maximum (const T a, 
    		      const T b)
      { return ( (a<b) ? b : a ); }
    
    tcT inline boolean minimize (T &a, 
    			     const T b)
      // Reqturn: true iff a is changed
      { if ( a>b ) {a=b; return true;} else return false; }
    
    tcT inline boolean maximize (T &a, 
    			     const T b)
      // Reqturn: true iff a is changed
      { if ( a<b ) {a=b; return true;} else return false; }
    
    tcT inline int sgn (const T a)
      { return ( (a>0) ? +1 : -1 ); }
    
    tcT inline int tsgn (const T a)
      { return ( (a>0) ? +1 : ( (a<0) ? -1 : 0 ) ); }
    
    tcT inline int tcomp (const T a, 
    		      const T b)
      { return ( (a<b) ? +1 : ( (a>b) ? -1 : 0 ) ); }
    
    inline boolean Even (lint X)
      { return X % 2 == 0; }
    
    
    boolean EqualFloat (double X, double Y);
         
    boolean NullFloat (double X);
    
    boolean GreaterEqualFloat (double X, double Y);
    
    boolean LessEqualFloat (double X, double Y);
    
    inline boolean GreaterFloat (double X, double Y)
      { return  ! LessEqualFloat (X, Y); }
    
    inline boolean LessFloat (double X, double Y)
      { return  ! GreaterEqualFloat (X, Y); }
    
    inline boolean Positive (double X) 
      { return  GreaterFloat (X, 0); }
      
    inline boolean Negative (double X) 
      { return  LessFloat (X, 0); }
      
    inline boolean BetweenFloat (double X,
    			     double L,
    			     double U)
      { return  GreaterEqualFloat (X, L) && LessFloat (X, U); }
    
    inline boolean BetweenEqualFloat (double X,
    				  double L,
    				  double U)
      { return  GreaterEqualFloat (X, L) && LessEqualFloat (X, U); }
    
    
    double Sqr (double X);
      // Return: X * X 
    
    
    
    // Infinities, NaN
    extern const double INF;
    extern const double NAN;
    
    boolean IsNanOrInf (double X);
      // Inf - positive or negative
    
    boolean IsInf (double X);
      // Inf - positive or negative
    
    
    
    // Random
    double  randomR ();
      // Return: 0..1
     
    uint    randomI (uint n);
      // Return: 0..n-1
    
    boolean flipAtail ();
    
    void    fixSeed (lint SeedVal);
    
    double  RandomExponential (double Mean);
    
    
    
    
    #endif
    Last edited by Salem; 05-30-2009 at 07:17 AM. Reason: Added code tags, learn to use them yourself

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    Wow - no code tags - sheesh!!!
    Fixed
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    void SubstituteVariables (char* S)
    {
      if (StrIsEmpty (S))
        return;
    
    
      ForEver
        {
          char* VarStart = strstr (S, "(*");
          if (VarStart == NULL)
    	break;
    
          for (uint i = 2; VarStart [i] != 0 && VarStart [i] != ')'; i++);
          assert (VarStart [i] != 0);
    
          uint VarNum;
          if (sscanf (& VarStart [2], "%u", & VarNum) != 1)
    	RunError;
          assert (VarNum > 0 && VarNum <= MaxVarNum);
    
          StrReplace (VarStart, i + 1, Variable [VarNum - 1]);
        }
    }
    That i is only in scope in the bolded line (within the for-loop where it is declared) unless you are using a pre-standard compiler (like VC6).

    Code:
    enum     {false, true, BooleanDontKnow};
    false and true are keywords in C++, hence you can't use them as names for enumerated values.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 06-17-2005, 11:00 PM
  2. Novice trying to learn C++
    By dead in forum C++ Programming
    Replies: 10
    Last Post: 12-01-2003, 09:25 PM
  3. Rtfm
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-13-2003, 05:19 PM
  4. help for a C novice
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 05-02-2002, 10:49 PM
  5. Please help a novice
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2002, 10:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21