Well, the program is designed to remove any text between the /* and */ in a text file input and also to give output of the original text. Copying the original text was easy, but I'm having trouble 'removing' text in between the /* and */ in a text file.
Say for example, a.txt had this:
/* Blah2 */ text /* /* Blah */ */
The output should be:
text /* Blah */
Heres wat I've done so far, I'm having trouble checking for /* and */ since they are 2 characters and getc() only returns one.. so any ideas?
Code:#include <stdio.h> #include <stdlib.h> // Formatting Constants #define LINE "----------------------------" // FILE* is a pointer variable void original(FILE*); void extractor(FILE*); int main(int argc, char **argv) { // Point to a File FILE *fp; fp = fopen(argv[1],"r"); if (argc != 2) { printf("Please input a text file (one is required no more)\n"); } else { fprintf(stdout, "Removing /* and */ signs from %s...", argv[1]); // Check for contents in file fprintf(stdout, "\n"); fprintf(stdout, "%s\n",LINE); fprintf(stdout, "Original contents of: %s\n",argv[1]); // Print out original contents original(fp); // Print out extracted (modified) contents fprintf(stdout, "%s\n",LINE); fprintf(stdout, "Extracted contents of: %s\n",argv[1]); extractor(fp); // Close file fprintf(stdout, "%s\n",LINE); fclose(fp); } return 0; } void original(FILE *fp) { int c; while ((c = getc(fp)) != EOF) { putchar(c); } return; } void extractor(FILE *fp) { int c; while ((c = getc(fp)) != EOF) { /************************/ /* NEED TO FINISH THIS PART */ /************************/ } return; }



LinkBack URL
About LinkBacks


