pengguna_komputer 0 Report post Posted August 28, 2005 Satu lagi soklan basic..saya mengompilkan source code dibawah menggunakan gcc.#include <stdio.h> main() { char szNama[75]; printf("Sila masukkan nama anda\n"); gets(szNama); printf("Apakhabar %s\n", szNama); return 0; } ia akan menghasilkan error seperti dibawah, tetapi program masih boleh digunakan. cc mygets.c /tmp/ccA6hNRP.o(.text+0x34): In function `main': : warning: the `gets' function is dangerous and should not be used. Kalu ader alternatif lain, sila kongsi... Quote Share this post Link to post Share on other sites
da^hype 0 Report post Posted August 28, 2005 (edited) kau pakai compiler apa? aku run program kau tu in VS 6.0 and VS 7.3.. takde masalah.in u're code. char szNama[75];an input longer than 74 characters will overrun the szNama buffer and almost certainly cause the program to crash.also, read up on fgets Edited August 29, 2005 by da^hype Quote Share this post Link to post Share on other sites
pengguna_komputer 0 Report post Posted August 29, 2005 kau pakai compiler apa? aku run program kau tu in VS 6.0 and VS 7.3.. takde masalah.←Compiler yg digunakan..rpm -qa | grep gcc gcc-3.4.4-2Saya compile pakai Borland Turbo C pon tak de masalah jugak..Skrang ni tengah baca pasal fgets Quote Share this post Link to post Share on other sites
1kHz 0 Report post Posted August 29, 2005 tu bukan error, tapi warning.. error dan warning benda berlainan..aku tak berapa tahu, tapi aku rasa ada kaitan dgn buffer-overflow/overrun ..http://www.google.com/search?q=the+%60gets...+not+be+used%2E Quote Share this post Link to post Share on other sites
da^hype 0 Report post Posted August 29, 2005 tu bukan error, tapi warning.. error dan warning benda berlainan..aku tak berapa tahu, tapi aku rasa ada kaitan dgn buffer-overflow/overrun ..http://www.google.com/search?q=the+%60gets...+not+be+used%2E←yeah i think so too. Quote Share this post Link to post Share on other sites
pengguna_komputer 0 Report post Posted August 29, 2005 Thanks pada suma yang bantu n bagi hints kat sayaHasil ujikaji cket, gets memang tak secure dan boleh menyebabkan buffer overrun, so fgets digunakan untuk atasi masalah ni...Kod dibawah ni menggunakan fgets.#include <stdio.h> main() { char szNama[75]; printf("Sila masukkan nama anda\n"); fgets(szNama,75,stdin); printf("Apakhabar %s", szNama); return 0; } Boleh dikompil tanpa warning msg. Quote Share this post Link to post Share on other sites
da^hype 0 Report post Posted August 29, 2005 cool Quote Share this post Link to post Share on other sites