Small Programs sample source codes(Translate all DOT'S -056, except for the last one)
Translate all DOT'S -056, except for the last one
#include <>
#include <>
#include <>
#define PACKAGE "dedot"
#define VERSION "1.0.0"
#define MAXLINE 1024
void print_help(int exval);
int main(int argc, char *argv[]) {
char line[MAXLINE];
char *ptr = NULL; /* points to the last dot */
char sub_char[1]; /* substidute char */
int sub_set = 0; /* substitude set ? */
int all_flag = 0; /* print all lines, even the ones not subject to change */
/* 1=on, 0=off */
int i = 0;
int opt;
while((opt = getopt(argc, argv, "hac:")) != -1) {
switch(opt) {
case 'h':
print_help(0);
break;
case 'a':
all_flag = 1;
break;
case 'c':
sub_set = 1;
strncpy(sub_char, optarg, 1);
break;
case ':':
fprintf(stderr, "%s: Option `%c' needs an argument `-c CHAR' ?\n\n",
PACKAGE, optopt);
print_help(1);
break;
case '?':
fprintf(stderr, "%s: No such option `%c'\n\n", PACKAGE, optopt);
print_help(1);
break;
} /* switch */
} /* while */
while((fgets(line, 1024, stdin)) != NULL) {
if((ptr = strrchr(line, '.')) == NULL) {
if(all_flag == 1)
printf("%s", line);
continue;
}
for(i = 0; i < strlen(line); i++)
if(sub_set == 1 && line[i] == '.' && &line[i] != ptr)
printf("%c", sub_char[0]);
else if(line[i] != '.' || &line[i] == ptr)
printf("%c", line[i]);
}
return 0;
}
void print_help(int exval) {
printf("%s,%s remove every dot `.' exept for the last one\n", PACKAGE, VERSION);
printf("%s [-h] [-c CHAR]\n\n", PACKAGE);
printf(" -h print this help and exit\n");
printf(" -c CHAR substitude all dots EXCEPT the last one with character `CHAR'\n");
printf(" -a print all lines, even the ones which are not subject of change\n\n");
exit(exval);
}
Read more: http://cmagical.blogspot.com/2010_02_14_archive.html#ixzz0xgXcuCoR
Under Creative Commons License: Attribution Non-Commercial No Derivatives
Labels
- ajax (1)
- Assembly Programming (3)
- Books on C++ (6)
- C Programs (35)
- Challenging Question (1)
- Class (1)
- Complete Script (1)
- Computer Graphics (1)
- CSS (2)
- Datastructure (6)
- Download (3)
- e-books (8)
- Errors (1)
- FTP (2)
- HTML (3)
- Interview Questions (8)
- Introduction (1)
- Methods (2)
- OOP (1)
- Operator Overloading (1)
- Operators (1)
- Others (5)
- PHP (4)
- PHP Errors (1)
- PHP Script (1)
- Programming (3)
- Question Bank (6)
- Short Questions (1)
- SQL (1)
- Tips (1)
- Tricks (1)
- Tricky Programs in C (2)
- Useful Scripts (1)
- WAP (1)
- Web (3)
- XHTML (1)
Small Programs sample source codes(Translate all DOT'S -056, except for the last one)
Wednesday, August 25, 2010Posted by Xofth at 10:00 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment