C言語なら俺に聞け(入門篇) Part 17
■ このスレッドは過去ログ倉庫に格納されています
0488デフォルトの名無しさん
2007/08/07(火) 02:45:00#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 64
void operate(char **s1,char **s2){
char data[N],temp[N],*ptr,*ch;
fgets(data, N, stdin);
ptr = strstr(data, "lemon");
strncpy(temp,ptr,strlen("lemon"));
temp[strlen("lemon")] ='\0';
*s1 = malloc(strlen(temp)+1);
strcpy(*s1,temp);
if((ch = strchr(ptr,'l'))!=NULL) *ch = 'm';
if((ch = strrchr(ptr,'m'))!=NULL) *ch = 'l';
if((ch = strchr(ptr,'n'))!=NULL) *(ch+1) = '\0';
*s2 = (char *)malloc(strlen(ptr)+1);
strcpy(*s2, ptr);
}
int main(){
char *str1=NULL,*str2=NULL;
operate(&str1,&str2);
printf("str1 = %s str2 = %s\n", str1,str2);
free(str1);free(str2);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています