Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created January 1, 2009 14:39
Show Gist options
  • Save hitode909/42283 to your computer and use it in GitHub Desktop.
Save hitode909/42283 to your computer and use it in GitHub Desktop.
// 変だったところをちょっと直しました
#include<stdio.h>
#include<stdlib.h>
int main(void) // main関数の宣言が変だった
{
char *name[10];
char *buff;
int i;
// Input
printf("\n*** Fanction of Malloc test ***\n");
for(i = 0; i < 10 ; i++){
buff = malloc(sizeof(char) * 100); // mallocはキャストしなくていいので修正
name[i] = buff; // name[i]が指す番地をbuffに(ここが一番の間違い)
fgets(buff, 100, stdin); // getsを使うと警告が出るのでfgetsに変更
}
for(i = 0; i < 10 ; i++)
printf("%p\n", name[i]); // メモリの番地を表示するときは%pで
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment