prog3 working with prof open code

prog3 working with prof open code - /* function definition...

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> 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]; 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]0; exit (1); } fp2 = fopen(argv[2], "w"); fgets(lLineIn, 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); fprintf(fp2, "%s\n", 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)
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: /* function definition */ { int s_length = strlen(s); int p_length = strlen(p); int count = 0; /* line 40 */ for(int i=0; i&lt;=(s_length - p_length); i++) { /* printf(&quot;%d\n&quot;, i);*/ for(int k=0; k&lt;p_length; k++) { /* printf(&quot;%d\n&quot;, k );*/ if(s[i+k] == p[i+k]) { count++; } if(count == p_length) { for(int l=0; l&lt;i; l++) { *(sl+l) = s[l]; } for(int m=(i+k+1); m &gt;= s_length; m++) { *(sr+m) = s[m]; } /* line 60 */ return 1; } } } /* printf(&quot;%d\n&quot;, count);*/ /* printf(&quot;%s\n&quot;, s);*/ if(count != p_length) { strcpy(sr,&quot;&quot;); /*69*/ strcpy(sl , s); printf(&quot; sl is %s\n&quot;, sl); printf(&quot; sr is %s\n&quot;, sr); /*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 code - /* function definition...

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