String input using C scanf_s

后端 未结 5 1171
刺人心
刺人心 2020-12-11 08:42

I\'ve been trying to look for answer myself, but I can\'t find one. I want to insert a part of the programming that reads in a string like \"Hello\" and stores and can disp

5条回答
  •  暖寄归人
    2020-12-11 08:57

    you should do this : scanf ("%63s", name);

    Update:

    The below code worked for me:

    #include  
    int main(void) { 
        char name[64]; 
        scanf ("%63s", name); 
        printf("Your name is %s", name); 
        return 0; 
    }
    

    if you are using visual studio, go to Project properties -> Configuration Properties -> C/C++-> Preprocessor -> Preprocessor Definitions click on edit and add _CRT_SECURE_NO_WARNINGS click ok, apply the settings and run again.

    Note: this is only good if you are doing your homework or something like that and it's not recommended for production.

提交回复
热议问题