Thread: Operating Environment

  1. #1
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Operating Environment

    um, yeah, Im writing a operating environment for DOS - its call UCP/OS and at the moment its not very good - has anyone got any tips? ive been writing c 4 about 1 1/2 years and im still not very gd at it!
    Kree'ta Tau'ri! Chaapa'ai!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Operating Environment

    Originally posted by Unimatrix139
    um, yeah, Im writing a operating environment for DOS - its call UCP/OS and at the moment its not very good - has anyone got any tips? ive been writing c 4 about 1 1/2 years and im still not very gd at it!
    If you're having probs with a particular bit, post some code. Else do some web research etc.....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55
    Okay, thanx hammer...


    I have this program I build
    Code:
     /* void spawnr(int a)
    {
       if(a==1)
       {
          cmd2attr();
          return(0);
       }
       fp=fopen("cmd2attr.tmp", "r");
       if(fp==NULL)
       {
          error(2, "C2A/3: cmd2attr.tmp");
          return(0);
       }
       starstring=fgets(sizedstring1, 701, fp);
       starstring2=fgets(sizedstring2, 701, fp);
       fclose(fp);
       stdint1=atoi(starstring2);
       stdint2=strlen(starstring);
       fp=fopen("cmd2attr.tmp", "w");
       do
       {
          if(sizedstring1[stdint1]==' ')
          {
             fprintf(fp, "\n");
             stdint1=stdint1+1;
          }
          if(sizedstring1[stdint1]!='\n')
          {
             fprintf(fp, "%c", sizedstring1[stdint1]);
             stdint1=stdint1+1;
          }
          else
          {
             stdint1=stdint2;
          }
       }
       while(stdint1<stdint2);
       fclose(fp);
       return(0);
    }
    cmd2attr()
    {
       fp=fopen("cmd2attr.tmp", "r");
       if(fp==NULL)
       {
          error(2, "C2A2: cmd2attr.tmp\n");
          return(0);
       }
       starstring=fgets(sizedstring1, 701, fp);
       starstring2=fgets(sizedstring2, 701, fp);
       fclose(fp);
       stdint1=atoi(starstring2);
       stdint2=strlen(starstring);
       fp=fopen("cmd2attr.tmp", "w");
       do
       {
          fprintf(fp, "%c", sizedstring1[stdint1]);
          stdint1=stdint1+1;
       }
       while(stdint1<stdint2);
       fclose(fp);
       return(0);
    }
    
    */
    it's ment to split a command typed at the prompt of my OE into its compnents - eg. Command Argument are put into a file, and the program puts them into a file beneath each other for the OE to pick up. Only its really slow and naff, and it cant cope with multiple arguments. Is there any other way to do it? thanx!
    Kree'ta Tau'ri! Chaapa'ai!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK, you've completely lost me....

    What is your code supposed to do again? Read input from the user? Where do you attempt to do that?

    If you are simply trying to split a string up based on the space character, you can adapt something like this.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	FILE *fp;
    	int len, i;
    	char buf[BUFSIZ], *ptr;
    	
    	if ((fp = fopen("junk1.c", "r")) == NULL)
    	{
    		perror("junk1.c");
    		return 1;
    	}
    	
    	while (fgets(buf, BUFSIZ, fp))
    	{
    		buf[BUFSIZ-1] = '\0';		
    		for (ptr = buf; *ptr != '\0'; ptr++)
    		{
    			if (*ptr == ' ')
    				putchar('\n');
    			else
    				putchar(*ptr);
    		}
    	}
    	
    	fclose (fp);
    	
    	return 0;
    }
    Note that you won't be able to read/write from the same file easily. It'd be better to write to a temp file first, then rename it in later (well..... maybe, depending on what else you're app is doing).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Talking

    I think ive lost me 2, but nvr mind! I think wot u put will work.... Im not sure, but there u go!!! Thanx sooo much!!
    Kree'ta Tau'ri! Chaapa'ai!

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    Hi,

    I think writing/using a small command-line parser would be of immense help. Coding in Lex & Yacc should get your job done in not much time. If you wish to write your own parsing code though, try out recursive-descent parsing - it is easy to code and doesn't take long.

  7. #7
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55
    um... thanx but i dont really understand.... :d
    Kree'ta Tau'ri! Chaapa'ai!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (VC++ related) Unicode or Multi-byte environment?
    By PaulBlay in forum C Programming
    Replies: 3
    Last Post: 05-22-2009, 08:42 AM
  2. Childrens' operating environment?
    By Imagine in forum Tech Board
    Replies: 9
    Last Post: 01-30-2009, 01:23 AM
  3. 16-bit and 32-bit environment or compiler
    By hitesh_best in forum C Programming
    Replies: 3
    Last Post: 10-03-2007, 11:12 PM
  4. Why Can't C++ Be Used to Develop Operating System?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2005, 06:16 AM
  5. Operating environment
    By Unimatrix139 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-08-2002, 03:43 AM