Sử dụng hàm gets báo lỗi unsafe trên Visual Studio?

Error	1	error C4996: 'gets': This function or variable may be unsafe. Consider using gets_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	d:\visual studio 2013\projects\struct\danh sach hoc sinh\hocsinh.cpp	8	1	danh sach hoc sinh

visual từ 2012 trở lên thì dùng gets_s (secure) thay cho gets

3 Likes

đã thay rồi :smiley: tks huy. mà nó lỗi khác

1 Like

Em có thể sử dụng hàm fgets thay thế nha

#include <stdio.h>
#include <string.h>

int main()
{
    char str[2];
    printf("len of str %d\n", strlen(str));
    printf("size of str %d\n", sizeof str);
    fgets(str, 2, stdin);
    printf("str: %s\n", str);
    printf("new len of str %d\n", strlen(str));
    printf("size of str %d\n", sizeof str);
    return 0;
}

P/S: Mới nãy viết một đống mà bấm nhầm hủy, thành ra mất bài. Ức chế quá. Lát có hứng viết lại bài này, lý do tại sao gets không an toàn.

1 Like

cảm ơn anh nhiều. :love_letter:

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?