Last active
August 29, 2015 14:01
-
-
Save ktnyt/0bcc5338fd3a8b7d57c1 to your computer and use it in GitHub Desktop.
Let's nyan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAXLINE 256 | |
int main() { | |
char str1[MAXLINE]; | |
char str2[MAXLINE]; | |
char str3[MAXLINE]; | |
char *s; | |
char tmp[MAXLINE*4]; // 4回結合用 | |
printf("String 1: "); | |
fgets(str1, MAXLINE, stdin); | |
printf("String 2: "); | |
fgets(str2, MAXLINE, stdin); | |
printf("String 3: "); | |
fgets(str3, MAXLINE, stdin); | |
s = strchr(str1, '\n'); | |
if(s != NULL) { | |
*s = '\0'; | |
} | |
s = strchr(str2, '\n'); | |
if(s != NULL) { | |
*s = '\0'; | |
} | |
s = strchr(str3, '\n'); | |
if(s != NULL) { | |
*s = '\0'; | |
} | |
// Method 1 | |
strcpy(tmp, ""); // tmpを初期化 | |
strcpy(tmp, str1); | |
strcat(tmp, str2); | |
strcat(tmp, str3); | |
printf("%s\n", tmp); | |
// Method 2 | |
strcpy(tmp, ""); // tmpを初期化 | |
strcat(strcat(strcat(tmp, str1), str2), str3); | |
printf("%s\n", tmp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment