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!
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!
If you're having probs with a particular bit, post some code. Else do some web research etc.....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!
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Okay, thanx hammer...
I have this program I buildit'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!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); } */
Kree'ta Tau'ri! Chaapa'ai!
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.
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).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; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
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!
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.
um... thanx but i dont really understand.... :d
Kree'ta Tau'ri! Chaapa'ai!