- อย่าลืมเปลี่ยนชนิดพอร์ยเตอร์ที่ได้มาจาก malloc ก่อนการใช้งาน
- อย่าจองหน่วยความจำมากเกินความจำเป็น บางเครื่องอาจจะมีแรมน้อยกว่าเครื่องของคุณ
- puts () ; จะทำการขึ้นบรรทัดใหม่ให้อัตโนมัต
- gets() ; จะไม่รับตัวขึ้นบรรทัดใหม่ ‘\n’ เข้าไปไว้ในอาร์กิวเมนต์
- malloc : http://www.cplusplus.com/reference/cstdlib/malloc/
- gets : http://www.cplusplus.com/reference/cstdio/gets/
- puts : http://www.cplusplus.com/reference/cstdio/puts/
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> | |
int main(void) | |
{ | |
setbuf(stdout,NULL); | |
//1000000000 | |
//char comment[1000000000]; | |
char *pcm; | |
pcm = (char *) malloc(1000000000 * sizeof(char)); | |
if(pcm != NULL) | |
{ | |
printf("You are good to go\n"); | |
gets(pcm); | |
puts(pcm); | |
} | |
else | |
{ | |
printf("Insufficient memory"); | |
} | |
return 0; | |
} |