Thread: Is this a compiler Issue?

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    Is this a compiler Issue?

    This code works:
    Code:
    /*
    Compiled under Turbo C 2.01
    DO NOT COMPILE WITH WINDOWS
    GCC! I haven't tried any
    other compilers.
    */
    
    #include <stdio.h> /* For output/input */
    #include <stdlib.h> /* For system() */
    #include <string.h> /* For strcmp() */
    #include <unistd.h> /* For getcwd() */
    
    int main()
    {	
    	/* The users' command */
    	char input[16];
    
    	/* Path variables( getcwd() ) */
    	char *ppath; /* Pointer to PATH */
    	int ipath; /* Size of PATH */
    
    	/* Special Command Strings */
    	char root[3] = "\\\n";
    	char quit[6] = "quit\n";
    	char ls[4] = "ls\n";
    
    	for(;;)
    	{
    		getcwd(ppath,ipath); /* Get the current directory */
    		printf("%s>",ppath); /* mimic DOS prompt */
    		fgets(input,16,stdin); /* Get the input */
    
    		/* Check for "special" commands
    		(which are really simple DOS commands)
    		If not, then let DOS execute the
    		command.*/
    		if((strcmp(input,root) == 0) || (strcmp(input,quit) == 0) || (strcmp(input,ls) == 0))
    		{
    			if(strcmp(input,root) == 0)
    			{
    				system("cd \\");
    			}
    			if(strcmp(input,quit) == 0)
    			{
    				return 0;
    			}
    			if(strcmp(input,ls) == 0)
    			{
    				system("dir");
    			}
    
    		}
    		else
    		{
    			system(input);
    		}
    	}
    }
    But if I add
    Code:
    /* Welcome */
    printf("Welcome to DOS/ENHANCE! ");
    after the start of int main, my compiler gives my expression errors. I'm using Turbo C 2.01. I don't see anything wrong with my new code. Is this just a compiler problem?

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    102
    Could you post what the errors are? It could be usefull in figuring out what the problem is.

  3. #3
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    are you doing this?
    Code:
     int main()
    {
        printf("Welcome to DOS/ENHANCE! ");
        /* The users' command */
        char input[16];
    
        /*Path variables( getcwd() ) */
        char *ppath; /* Pointer to PATH */
        int ipath; /* Size of PATH */
    
         /* Special Command Strings */
         char root[3] = "\\\n";
         char quit[6] = "quit\n";
         char ls[4] = "ls\n";
        
         /* Rest of your code here */
    
    }
    just going from what you said.. if this is what you did then you got errors because in C you have to declare variable at the start of a function before you can do anything else.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  4. #4
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    ??

    I have to declare ALL variables at the start?
    OK. I'll try that.

  5. #5
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    yes. only C++ will let you declare a variable almost anywhere.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    102
    While that is true that its not proper C to declare variables on the fly... most compilers can handel them on the fly. I know that GCC 3.3 under linux can. Also IMHO its bad form to declare variables on the fly.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    124
    My compiler doesn't have <unistd.h> but i have the function getcwd() in <dir.h>.

    dir.h is a standard library?
    Loading.....
    ( Trying to be a good C Programmer )

  8. #8
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    No

    I think that dir is specific to DOS. I don't think that unistd.h is even ANSI. But, I'm not the one to know of such things

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    34

    Wink unistd.h | dir.h

    unistd.h : UNIX(R)
    dir.h Micro$oft DOS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev C++ Compiler, Indentation?
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:13 AM
  2. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM
  3. MSVC++ vs GCC compiler issue
    By WDT in forum C++ Programming
    Replies: 9
    Last Post: 01-04-2004, 01:07 PM
  4. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM
  5. Compiler Issue
    By spd_dmn in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2002, 01:29 PM