prog3 working

prog3 working - /* line 40 */ for(int i=0; i<=(s_length...

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(void) { /*declaring variables*/ char entered[250]; char LineIn[250]; char LineOut[250] = ""; /* line 20 */ char LineFinal[250]; char equals_sign[2]; char bad_string[10]; strcpy(LineOut , ""); strcpy(LineFinal , ""); strcpy(equals_sign , "="); strcpy(bad_string , "&!@#$%&*+"); while(scanf ("%s", LineIn)) { removep(LineIn, bad_string, LineOut); printf("%s\n", LineOut); removep(LineOut, equals_sign, LineFinal); printf("%s\n", LineFinal); } } /*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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
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: /* line 40 */ for(int i=0; i<=(s_length - p_length); i++) { /* printf("%d\n", i);*/ for(int k=0; k<p_length; k++) { /* printf("%d\n", k );*/ if(s[i+k] == p[i+k]) { count++; } if(count == p_length) { for(int l=0; l<i; l++) { *(sl+l) = s[l]; } for(int m=(i+k+1); m >= s_length; m++) { *(sr+m) = s[m]; } /* line 60 */ return 1; } } } /* printf("%d\n", count);*/ /* printf("%s\n", s);*/ if(count != p_length) { strcpy(sr,""); /*69*/ strcpy(sl , s); printf(" sl is %s\n", sl); printf(" sr is %s\n", 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("Remove L:%s\n", left_string); printf("Remove R:%s\n", right_string); } strcpy(t,s); }...
View Full Document

This note was uploaded on 09/28/2011 for the course CS 1113 taught by Professor Chandler during the Fall '08 term at Oklahoma State.

Page1 / 3

prog3 working - /* line 40 */ for(int i=0; i<=(s_length...

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