Skip to main content

Questions tagged [gets]

Anything related to C or C++ standard library functions gets (C) or std::gets (C++). These functions are used to read a sequence of characters from an input stream and to write it into a character buffer as a string. DO NOT USE THESE FUNCTIONS: they are deprecated, and since C11 gets is no longer part of the standard.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

Why VLA is comparable to gets?

It is well-known that MSVC doesn't, and won't support VLA feature. During searching MSVC online reference, I found somewhat interesting sentence: Variable length array (VLA) support isn't planned. ...
Venusaur's user avatar
  • 191
0 votes
2 answers
78 views

How can I use a Pointer to structure in C? [duplicate]

I have problem with pointer to structure in C. This is my code : #include <stdio.h> #define N 10 // determine the number of students typedef struct { char* firstname; char* lastname; ...
Lemony_79's user avatar
0 votes
1 answer
383 views

how to use observable File variable in Getx controller

I am trying to use the observable File variable in Getx but it shows an error. and I don't know another option to make the File observable in getx. Error [Get] the improper use of a GetX has ...
Manish sahu's user avatar
1 vote
2 answers
66 views

How to avoid This Segmenation Fault Error in Structure

This is my code: #include <stdio.h> struct book { char title[30]; char author[30]; char isbn[30]; float price; }books[5]; int main() { int i=1,j=0; while(i<6) { ...
Alan Mathew's user avatar
1 vote
0 answers
65 views

Reading from a File in C , problems with fscanf functions

My program is supposed to read from a file and fill some structs that are like post from a social network , and then fill a Queue structure with the info from the file. But the main problem seems to ...
Offsky's user avatar
  • 21
1 vote
1 answer
81 views

can't input string with space in c structure

I wanted to write a program to generate student mark list. But in this one, i can only insert first part of the name. the rest is skipped. i looked most forums about this problem and it still happens. ...
Ameen Aslam's user avatar
0 votes
0 answers
40 views

gets and scanf way of reading input [duplicate]

I have a simple code that I wrote to differentiate the way gets and scanf scan code, I've read about their differences and I understand them, my problem specifically is with the output that gets show. ...
Leon's user avatar
  • 1
1 vote
1 answer
36 views

Problem with gets function on array of strings in C

A few line of code bellow. When program execute I can input only 2 string without problem regardless what number is n, and then input loop stops. It shows ''Input 3. string'', ''Input 4. string'' etc ...
KeyboardSound's user avatar
-3 votes
1 answer
77 views

Why string[10] containing more 10 character in c? [duplicate]

I'm taking array of character size of 10 , but in return it gives me out-range array(10+) string, YOU CAN REFER TO MY CODE #include<stdio.h> int main(){ char name[10]; `array of 10 Character`...
Danish Khatri's user avatar
2 votes
4 answers
155 views

How to write the code correctly in Ruby? So that it produces the correct output?

I want to do something like that. puts "Please write your age: " age = gets.chomp if #{age}<18 puts "you are illegal" else #{age}>18 puts "You are legal" end ...
eb1212's user avatar
  • 23
1 vote
0 answers
33 views

gets() function not working as expected in C [duplicate]

I made a structure and tried obtaining the name using gets(). It worked for the first iteration but accepted nothing for the next iterations. #include <stdio.h> struct student{ int rollno; ...
Zeus Legend's user avatar
0 votes
0 answers
23 views

Extract the line from the file, concatenate it with a certain string problem

I have a problem, in the text file I have the form "User:Username Password,Real name Real Surname Email" and so on several lines, how can I add the word "(suspended)" to the ...
Andew Tayloe's user avatar
0 votes
2 answers
75 views

Void pointer and attributer constructor in a vulnerable code

I am supposed to find the vulnerability in the code and i feel its hidden either in the __attribute__((constructor)) or the pointer .Here i can make out that it's a void pointer but i have never ...
Haaziq Jamal's user avatar
0 votes
2 answers
311 views

the gets_s function in C language

I wrote a test program, in this progtam there is a menu function, which allows user to choose a thing he wants to do. And there is a thing, if he chooses a task, where function gets_s is located and ...
Kr1sp0's user avatar
  • 27
1 vote
1 answer
82 views

Why my program doesn't allow me to input b?

I want to input valors for a and b, being a an int and b a str. When I run my program I can input a valor, but then it ingnores printf() and gets() for b. #include<stdio.h>> int main() { ...
moyoloco09's user avatar
0 votes
1 answer
33 views

scan a splitted line of characters in C

I have been struggling scanning the following line of textfile into a char matrix : O A B C D E T What i tried was this : fscanf(ifs, "%c %c %c %c %c %c %c", graphe->name[0][0], graphe-&...
Adrien's user avatar
  • 36
0 votes
1 answer
44 views

cout is only working after gets() eventhough i had written it before gets()

I have just started learning c++. I wrote this program for finding how many vowels in a sentence. But when i run the program it asking for input before the cout and cout is working after gets() #...
Dilshad's user avatar
0 votes
1 answer
121 views

The fgets statement doesnt get executed

Here is my code for a simple programme in C for storing details of students in a struct. The problem that I am having is that the fgets statement for taking in the name string doesn't get executed and ...
Atharav Jadhav's user avatar
0 votes
3 answers
148 views

not terminating scanf() or gets() after taking newline

I have to take three inputs in a single string. The code to take the input is: char msg_send[1000]; gets(msg_send); The input is like GET /api HTTP/1.1 id=1&name=phoenix&mail=bringchills@...
User 1999's user avatar
0 votes
0 answers
24 views

Problem when using fgets for input of string [duplicate]

I had to write an assignment in C, where we had to define a structure and perform some operations on it. This is the code I have written: #include <stdio.h> struct student { char name[100]; ...
Raj Vichare's user avatar
0 votes
0 answers
56 views

I'm new to C and am stuck with many issues, I have fixed them but I wonder if there are better ways

I'm new to C just coming out of my second university class that explained structs and string functions. I tried running the code we had written in the lesson and ban, one segmentation error, "...
Kuudere-san's user avatar
-1 votes
1 answer
43 views

String not scanned 2nd time when using gets function [duplicate]

When I am using gets function to scan item name in the first loop it runs properly but in the 2nd loop, it skips to Quantity quant without scanning item name. I also tried using %s previously then it ...
Shashank Patil's user avatar
0 votes
2 answers
68 views

When we take input in a string why size does not matter?

#include<stdio.h>` int main() { char b[1]; scanf("%s",b); puts(b); // gets(b); // puts(b); // gets(b); // puts(b); return 0; } output: hello_world hello_world I ...
Gagandeep Singh's user avatar
1 vote
2 answers
713 views

Difference between "gets(s);" and "scanf("%s", s);" in C

I am writing a program that allows users to enter five names and sorts the names in Alphabet order, two adjacent names seperated by a newline character. Here is my code: void sortWords(char s[][100], ...
Nguyễn Xuân Hậu's user avatar
0 votes
1 answer
28 views

Trying to print a sring,but getting "@@" in place of data

I am trying to get a string from the user, then remove all characters in a string, except the alphabets. The string a string containing whitespace. I have input a string, but the output is only "@...
vivek upadhyay's user avatar
0 votes
3 answers
289 views

ruby how to keep decimals inside of a hash value with gets.to_i

I have price_input = gets.strip.to_i and I am trying to add it to an array of hashes. The adding to array works, but the .gets.strip.to_i removes any decimals. Is there a way to add it without it ...
savage's user avatar
  • 11
0 votes
1 answer
86 views

Ruby gets reading from file given as argument

I have a ruby script that is run with ruby myscr.rb ./text_file.txt that reads input with gets and writes it to the file, but gets seems to be reading from the file and not terminal input. How do I ...
Matthias Lee's user avatar
0 votes
1 answer
2k views

In which cases is scanf safe in terms of overflow? And in which cases must it necessarily be replaced by another function such as fgets?

It is usually said that scanf is not a safe function. Clang and GCC do not issue any warnings, but MSVC does not even compile (unless you include _CRT_SECURE_NO_WARNINGS): Error C4996 'scanf': This ...
Lucas's user avatar
  • 151
1 vote
1 answer
108 views

How to solve this gets() function problem?

In my program if I use scanf(), the program works fine. But as it is obvious, scanf() stops reading the input if it encounters a whitespace. So, instead I used gets(). But the problem is I have to use ...
Nureka Rodrigo's user avatar
-3 votes
2 answers
419 views

gets vs fgets for overflow in program

i have the following c program. when i enter input as bytebyte it is giving the wrong input due to buffer overflow. this is the program #include <stdio.h> #include <string.h> #include &...
cseprojects 14batch's user avatar
-4 votes
1 answer
80 views

Need to write a program acts like an integer calculator [closed]

New with CS, and new with C language. Please help with the program needs to support all +, -, *, /, % functions and return the user input equation's result. The program should be continuously ...
Jo W's user avatar
  • 1
0 votes
3 answers
405 views

taking input using gets with arrow operator not working? What's the Error?

What's the Error in this ? I tried taking input using arrow operator. #include <stdio.h> typedef struct{ char name[100]; int salary; }emp; void inp(emp *e){ printf("enter name : &...
Harshit's user avatar
1 vote
1 answer
142 views

What is the importance of adding "\n" to stdout when it's redirected to another process?

So, I'm playing with pipes in c, and I have an exercise where I call a program through command line as this: "./self 1" which then calls itself with execlp but with an argument 2: "./...
user410918's user avatar
0 votes
0 answers
34 views

How to fix this gets command in do while loop? [duplicate]

I cant fix this gets, the next output will be productname:Price: Can someone help me how to fix it? #include <stdio.h> int main() { int price,quantity,total,cash,change,equal; char ...
Newbie's user avatar
  • 3
0 votes
1 answer
102 views

why passing a char* argument to gets instead of a static array of char doesn't work? [duplicate]

I atentionally keep optional details for a best undersanding. say we want to store a string in a variable of char* : #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]){...
Simo's user avatar
  • 161
0 votes
1 answer
589 views

Alternative for gets in C

I need help optimizing the code below, it's been a while since I coded in C and something has changed since then. Write a program that asks for a name that compares to those that it has as elements ...
VII's user avatar
  • 1
0 votes
0 answers
60 views

Converting a string to a decimal : Assembly .586 [duplicate]

I am taking input from the end user using the gets() function and trying to convert that string to a number. From what I have found thus far, gets() stores the address of the string captured in eax ...
Topher's user avatar
  • 1
-1 votes
1 answer
564 views

Not able to take input using using gets( ) function [duplicate]

Q.1)Write a program to display user details as User name,Email,Contact no,Address each on new line. #include<stdio.h> #include<conio.h> void main(){ char username[25],Email[40],contact[...
 Kaif Bhombal's user avatar
0 votes
1 answer
190 views

What's wrong with my code? why gets function is not working?

I have declared 3 variables. here ch for store one character and s for store a single word and sen for a sentence or multiple words! But, when i run the code it is not giving the opportunity to give ...
Md Nasir Ahmed's user avatar
1 vote
1 answer
502 views

How to simulate multiple `gets` (user input) with RSpec

This project is a simple Ruby project, Github Repo, which I am trying to re-build using TDD, and I'm using Ruby (ruby 2.7.3) and rspec (RSpec 3.10). My issue is, no matter how I try to simulate user ...
sudo install's user avatar
-1 votes
4 answers
414 views

I have problem in string, in using the gets function, in c language

I have a problem with string in the c language we know, the string is known as a null-terminated character** array, in the string, we declare how many characters this string is store. and the memory ...
user avatar
4 votes
3 answers
267 views

Is there any gcc compiler option or something similar to bypass the obsolesence of the gets function?

Let's get this out of the way first: I am fully aware of why the gets function is deprecated and how it can be used maliciously in uncontrolled environments. I am positive the function can be used ...
Nu Nunu's user avatar
  • 394
1 vote
1 answer
227 views

Need Help Executing Simple Buffer Overflow

I am trying to execute a buffer overflow on this code: #include <stdio.h> CanNeverExecute(){ printf ("You should not be seeing this , right?\n"); } Greet(){ char buf [8]; ...
erinc's user avatar
  • 267
0 votes
2 answers
113 views

Can I use gets() and puts() of same string in different functions

#include <stdio.h> #include <string.h> struct employee { char ename[20]; int sal; }; struct employee accept(struct employee); void display(struct employee); void main() { ...
Aditya Bachu's user avatar
1 vote
2 answers
185 views

why couldn't use a pointer in gets in C? such as char *str replace char str[40] in gets(str)

#include <stdio.h> int main () { char str[40]; printf("Enter a string : \n"); gets(str); printf("You entered: %s\n", str); return 0; }; in above code, ...
John's user avatar
  • 11
0 votes
0 answers
26 views

Why the name of player 1 is not taking in the below code? [duplicate]

The question is on taking the total number of players in a game and then taking their names using gets() function !! I want to know Why the name of player 1 is not taking in the following code using ...
Rigel's user avatar
  • 1
1 vote
1 answer
2k views

I am currently working on Turbo c++ to be precise on c language

This is my program code: and the desired output is this (copied from https://www.javatpoint.com/c-gets-puts): and the output I am receiving is this I would be very pleased if anybody can highlight ...
Shayan ali's user avatar
0 votes
0 answers
26 views

Cannot understand how loop is running here [duplicate]

in this code on enter a number loop runs that many times but I can input data when loop runs for first time **clockformat is just a function that converts 12-hour clock to 24-hour clock #include<...
methead's user avatar
  • 15
-5 votes
1 answer
343 views

Why does my c code skip the printf line and goes straight to gets(array) [duplicate]

I am unsure why my code is skipping the printf after scanf. Only after I input my gets(array) does my printf print the statement. void stack_(void) { int amount; printf("PLease enter amount\t&...
LePiff's user avatar
  • 27
0 votes
0 answers
17 views

Code application stopping work after the second gets read [duplicate]

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdbool.h> #include <string.h> typedef struct jogador { char nome[30]; int idade; int ...
yuri fernandes's user avatar

1
2 3 4 5
9