Program to Remove the Dots From Line, 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;
char sub_char[1];
int sub_set = 0; /* substitude set ? */
int all_flag = 0;

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 <>
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);
}

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!