What is the function in c for built a string. | SoloLearn: Learn to code for FREE!

+1

What is the function in c for built a string.

c

5/20/2020 3:04:06 PM

Raman Kumar

3 Answers

New Answer

+2

Ok, but you should not be using gets() for input. it has no size arguments. The string buffer can be overrun if user enters string larger than your string size. gets() is so bad that they deprecated it in C99 and removed it from C11 standard. its better to use fgets(s, sizeof(s), stdin) for string input ,it will not write past your string size. for strings scanf() has same problem as gets() if you do not give it input range: scanf("%19s", s);

+1

@Jayakrishna🇮🇳 That code is dangerous! You have declared the string buffer as 20 characters in length then called fgets with a length of 100!!!

-1

No function use charecter array.. char s[100]; you can store in this a string.. Or by taking string input, you can store like Syntax: fgets(char_array, max_size_of_input, input_console) ; Ex: fgets(s, 100,stdin); or gets(s) ; //simple way for a line of string.... But not recommended as it is dengerous.. scanf("%s", s); //for single word of string Edit: Martin Taylor oh. Yes I am not given that relating to char array of s but just a random example.... I added fgets later, but forget to check and edit.. Ok thank for that correction.. Actually, Iam for the questioner response.. What actually he looking,.. And to give a answer accordingly with clear examples of possible but I got no response and I forgot it.....