-
-
Save hitode909/42283 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
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