|
Revision 966, 0.9 kB
(checked in by alpt, 2 years ago)
|
Initial revision
|
- Property svn:eol-style set to
native
- Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 |
#include <string.h> |
|---|
| 2 |
#include <ctype.h> |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
int isstrchar(char *str, int (*ischar)(int c)) |
|---|
| 6 |
{ |
|---|
| 7 |
while(*str && ischar(*str)) |
|---|
| 8 |
str++; |
|---|
| 9 |
return *str ? 0 : 1; |
|---|
| 10 |
} |
|---|
| 11 |
|
|---|
| 12 |
char *last_token(char *string, char tok) |
|---|
| 13 |
{ |
|---|
| 14 |
int i; |
|---|
| 15 |
while(*string == tok) |
|---|
| 16 |
string++; |
|---|
| 17 |
return string; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
void strip_char(char *string, char char_to_strip) |
|---|
| 21 |
{ |
|---|
| 22 |
int i; |
|---|
| 23 |
char *p; |
|---|
| 24 |
for(i=0; i<strlen(string); i++) { |
|---|
| 25 |
if(string[i]==char_to_strip) { |
|---|
| 26 |
p=last_token(&string[i], char_to_strip); |
|---|
| 27 |
strcpy(&string[i], p); |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
int main() |
|---|
| 35 |
{ |
|---|
| 36 |
char string[]="a line with spaces, too many spaces event \ttab"; |
|---|
| 37 |
printf("before: \"%s\"\n", string); |
|---|
| 38 |
strip_char(string, ' '); |
|---|
| 39 |
printf("after: \"%s\"\n", string); |
|---|
| 40 |
strip_char(string, '\t'); |
|---|
| 41 |
printf("after: \"%s\"\n", string); |
|---|
| 42 |
|
|---|
| 43 |
char *gh="UHiMMMMMMMM"; |
|---|
| 44 |
|
|---|
| 45 |
printf(": %s :", gh); |
|---|
| 46 |
|
|---|
| 47 |
if(!isstrchar(gh, isalpha)) |
|---|
| 48 |
printf("Negative\n"); |
|---|
| 49 |
else |
|---|
| 50 |
printf("Positive\n"); |
|---|
| 51 |
} |
|---|