prog3 working with prof open and pattern code

prog3 working with prof open and pattern code -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Matt Hergenrether CS2433 C/C++ Programming March 3, 2009 2:00pm */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> int split(char a[],char b[],char *c, char *d); /* function prototype */ void removep(char x[], char y[], char* z); /* function prototype */ void main (int argc, char * argv[]) { /*declaring variables*/ char entered[250]; char LineIn[250]; char LineOut[250]; char LineFinal[250]; char equals_sign[2]; char bad_string[10]; char *linefeedremoval; strcpy(LineOut , ""); strcpy(LineFinal , ""); strcpy(equals_sign , "="); strcpy(bad_string , "&!@#$%&*+"); FILE *fp1, *fp2; if(argc < 3) { printf("two command line arguments are required\n"); exit(0); } fp1 = fopen(argv[1], "r"); if (fp1 == NULL) { printf("%s could not be opened\n", argv [1]); exit (1); } fp2 = fopen(argv[2], "w"); fgets(LineIn, 250,fp1); while(!feof(fp1))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ removep(LineIn, bad_string, LineOut); removep(LineOut, equals_sign, LineFinal); linefeedremoval = strstr(LineFinal, "\n");
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: *linefeedremoval = '\0'; fprintf(fp2, &quot;%s\n&quot;, LineFinal); fgets(LineIn, 250, fp1); } fclose(fp1); fclose(fp2); } /*function searches for a pattern in a given string and removes it*/ int split(char s, char p, char *sl, char *sr) /* function definition */ { int s_length = strlen(s); int p_length = strlen(p); int count = 0; char *chptr; /* line 40 */ chptr = strstr(s,p); strcpy(sr,&quot;&quot;); if(chptr != NULL) { *chptr = '\0'; strcpy(sr, (chptr + p_length)); strcpy(sl, s); return 1; } else { /*69*/ strcpy(sl , s); /*70*/ return 0; } } void removep(char s, char p, char *t) /*function definition */ { char right_string[256]; char left_string[256] ; while(split(s, p, left_string, right_string )) { strcat(left_string, right_string); strcpy(s, left_string); printf(&quot;Remove L:%s\n&quot;, left_string); printf(&quot;Remove R:%s\n&quot;, right_string); } strcpy(t, s); }...
View Full Document

Page1 / 3

prog3 working with prof open and pattern code -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online