|
#include <stdio.h>
#include <stdlib.h>
#define MAX_STR 100
int main (int argc, char * argv []) {
int start, end, len;
char str [MAX_STR];
char output [MAX_STR];
if (argc <3) {
printf ("Not enough parameters!\n");
printf ("Usage:% s start end\n", argv [0]);
exit (0);
}
start = atoi (argv [1]);
--start;
end = atoi (argv [2]);
--end;
if (start> end) {
printf ("start> end!\n");
exit (0);
}
if (start <0) start = 0;
fgets (str, MAX_STR, stdin);
len = strlen (str);
if (end> len-1) end = len-1;
strncpy (output, str + start, end-start + 1);
output [end-start + 1] = '\0';
printf ("% s", output);
} |
|