hey guys, I was wondering if you can look over some code:
1. char* reverse(char *s);
*Here, s is a C-string. Its return value should be a newly-allocated C-string, said string being the reversal of the
string s. Hence, the return value of reverse("abcde") would be "edcba". *
2. char* trimfront(char *s);Code:{ char *t; int i, n; n=length(s); t = new char[n]; for (i=0; i<n; ++i) { *(t+i)=*(s+n-1-i); } *(t+i)='\0'; return t; } }
*Here, s is a C-string. Its return value should be a newly-allocated C-string, consisting of s, but with all initial whitespace characters removed*
3. char* trimrear(char *s);Code:{ while(*s == ' ' || *s == '\t') s++; return s; }
*Here, s is a C-string. Its return value should be a newly-allocated C-string, consisting of s, but with all final whitespace characters removed*
4. char* vowels(char *s);Code:char* trimrear(char *s) ( { char *s; s=str; while(*s){ ( if(isspace(*s)) s++; else break; ) return s; }
*Here, s is a C-string. Its return value should be a newly-allocated C-string consisting of all the vowels found in s, in the order found, taking case into account.*
(somebody was helping with this for me, but there seems to be a problem with the strcat)
Note: I am aware that there will be segmentation faults unless I include the new operator.Code:{ char* out = ""; for (i=0;i<strlen(s);i++) { char a = s[i]; switch (a) { case 'A': case 'a': case 'E': case 'e': // similarly i,o,u strcat(out,a); default: ; } // end switch } // end for return out; }
Thanks to everybody who helps..



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.