Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(void) {
- setbuf(stdout, NULL);
- puts("英字を削除します。");
- char s[2][15 + 1];
- for (int i = 0; i < 2; ++i) {
- printf("%d つめの文字列を入力\t: ", i + 1);
- char buf[BUFSIZ];
- if (!fgets(buf, BUFSIZ, stdin)) { exit(1); }
- for (char *p = buf; *p; ++p) {
- if (!isalnum(*p)) { *p = '\0'; }
- }
- int len = strlen(buf);
- if (15 < len) {
- puts("入力された文字列が多いです。"), --i;
- continue;
- }
- for (char *p = buf, *q = s[i]; *p || (*q = '\0'); ++p) {
- if (isdigit(*p)) { *q++ = *p; }
- }
- printf("英字の個数\t\t: %d\n", len - (int)strlen(s[i]));
- printf("削除後の文字列\t\t: %s\n", s[i]);
- }
- char t[15 * 2 + 1];
- if (strlen(s[1]) <= strlen(s[0])) {
- sprintf(t, "%s%s", s[0], s[1]);
- } else {
- sprintf(t, "%s%s", s[1], s[0]);
- }
- printf("連結された文字列は %s です。\n", t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement