What is the function in c for built a string. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the function in c for built a string.

20th May 2020, 3:04 PM
Raman Kumar
Raman Kumar - avatar
2 Answers
+ 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);
20th May 2020, 4:01 PM
Gen2oo
Gen2oo - avatar
- 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.....
20th May 2020, 3:15 PM
Jayakrishna 🇮🇳