したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | |

さらみ1

82名前とか無いよ、うん:2008/07/01(火) 22:35:28 ID:5fh3Nsws0
#include <stdio.h>
#include <stdlib.h>

char * myStringCopy(char *s, char *d);
int countChar(char *s);

int main(void)
{
char source[]="Hello";
char *destination;
char *result;
int size;

size = countChar(source);

destination = (char *) malloc( (size+1) * sizeof(char) );
if (destination == NULL) {
fprintf(stderr,"No Memory Space\n");
return 1;
}

result = myStringCopy(source,destination);
if (result == NULL) {
fprintf(stderr,"String Copy Action is Failed\n");
return 1;
}

fprintf(stdout,"%s\n",destination);

free(destination);

return 0;
}

/* NULL文字まで含めない文字数を返す */
int countChar(char *s)
{
int count = 0;
while (*s++) ++count;
return count;
}

char * myStringCopy(char *s, char *d)
{
char *ret = d;
if(!d || !s) return NULL;
while (*s) *d++ = (char)*s++;
*d = '\0';
return ret;
}

文字列をコピーする関数を作成せよ[C]
まあ、うんあれそんなんだった気がする


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板