Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uwm.edu!ogicse!pdxgate!eecs.cs.pdx.edu!jayward From: jayward@eecs.cs.pdx.edu (Jay Ward) Newsgroups: comp.sys.amiga.programmer Subject: Help for a budding C programmer? Message-ID: <1980@pdxgate.UUCP> Date: 16 Mar 91 06:16:21 GMT Sender: news@pdxgate.UUCP Reply-To: jayward@eecs.cs.pdx.edu (Jay Ward) Organization: Portland State University, Portland, OR Lines: 76 Hello! I am trying to convert from programming in Pascal to C and having a rather CHALLENGING time! If anyone can help, I would really appreciate it. I wrote the following program to split one file that contains a bunch of shar files (pulled from comp.binaries.amiga) into separate files (one per shar file). The program isn't even creating the proper filenames. NOTE: I tested the function OUTVERS separately and it seemed to work fine. ------ #include char * outvers(char *, int); main(argc, argv) int argc; char *argv[]; { FILE *infile, *outfile; int filecount; char b[80], *filename; infile = fopen(argv[1], "rb"); filecount = 1; while(fgets(b,80,infile) !=NULL) { filename = outvers(argv[2], filecount); outfile = fopen(filename, "wb"); while((b[0] != '#') && (b[1] != '-')) { fgets(b,80,infile);/* discard unneeded lines */ } while((b[0] != '-') && (b[1] != '-')) { printf("Outfile ==> %s\n", filename); printf("%s", b); fputs(b, outfile); /* save the good ones */ fgets(b,80,infile); } fclose(outfile); filecount++; } fclose(infile); } /* outvers will return a filename with the passed name followed by a single character extender letter that corresponds with the integer passed */ char * outvers(file, version) char *file; /* Needs a pointer to a string */ int version; /* and an integer */ { int i = 0; char filename[30]; /* go to end of string */ while(file[i] != '\0') filename[i] = file[i++]; filename[i++] = '.'; /* add a version extender */ filename[i++] = 64+version; filename[i++] = '\0'; return (char *) &filename; } ---- Thanks in advance! ---------------------------------------------------------------------------- Jay Ward --> jayward@eecs.cs.pdx.edu | if (TrailBlazers > Opponents) " " - Marcel Marceau | TrailBlazerWins++; ----------------------------------------------------------------------------