Most voted "scanf" questions
65 questions
Sort by count of
-
13
votes6
answers35893
viewsKeyboard buffer cleaning after scanf
I’m having trouble with the job scanf();. When reading two or more values, the later values are not read. I’ve already tried: __fpurge(stdin); After reading, but in this case I need to enter after…
-
9
votes1
answer4004
viewsHow to limit reading decimals (scanf) of a double variable?
The exercise asks the readings of the variables double are limited to only one decimal place each of them. I tried to put "%.1lf" in the scanf, as we used in the printf, but it didn’t work. How…
-
7
votes1
answer1284
viewsCin vs scanf, which is faster?
In competitive programming it is common for several programmers to use scanf() and printf() in C++ code instead of using cin and cout. And I’ve even seen problems that result in a Time Limit…
-
4
votes1
answer1222
viewsScanf is not stopping on repeat
I have a loop while which will only end when 0 (zero) is entered. I have a variable which will receive a command option. Inside the loop I own a switch marry where: 0) exits the program (returns to…
-
4
votes3
answers3650
viewsScanf function with variable amount of parameters, how to implement?
I have a text file (txt) that contains the following values: 12 90 These two values I keep and my variables a and b, that is to say a is equal 12 and b is equal 90, and I’m using the function…
-
4
votes1
answer1052
viewsParameters of the scanf function
When studying the function scanf with a little more depth I arose a doubt about the arguments I put before the % when reading a string, ie scanf("argumentos...%s",minhastring), in the following…
-
4
votes2
answers1292
viewsWhat’s best to use, scanf() or get_s()?
Taking the name 'Maria da silva' as an example: scanf() just go read Maria, get_s() will read it all, correct? I’m in doubt of the best use, my college professor says we should clean the buffer to…
-
3
votes2
answers768
viewsString of characters inside the scanf. Why and how does it work scanf("Day %d",&dia);?
Problem I was making a code that would read a string and then an entire value: int dia, h, m, s; char dp; //Dois pontos. scanf("Dia %d",&dia); //Inicio do evento. ... I thought of creating a…
-
3
votes2
answers110
viewsWhy does the order of these scanf’s make a difference in the outcome?
The program sums up x1 and x2 and puts the result in x1. It doesn’t work if x1 be read before x2. But if you reverse this order, it works. #include <stdio.h> #include <stdlib.h> unsigned…
-
3
votes1
answer634
viewsHow do I let the string size be set by scanf()?
My question is about the theory. I know it’s possible to make a string without limiting the size of the: char teste[] = "Teste"; however, I would like to know if it has how to do the same thing, ie…
-
3
votes3
answers69
viewsProgram does not meet expected flow by reading and printing input
#include <stdio.h> #include <stdlib.h> int main() { int num1, num2, num3; printf("Digite o numero A e numero B para saber o resto da divisao resultante da divisao entre eles:\n");…
-
2
votes1
answer1116
viewsHow to read a line in C
How to read a row of integers and store in a dynamically sized array ? Currently I read the line as string(although the input is only integers) using gets, only way it worked. The code is like this:…
-
2
votes1
answer909
viewsHow does buffer work using printf and scanf?
Using the printf, when I do: printf("\n\tQualquer coisa\n"); It inserts this first into a buffer and then prints to the screen (standard output) ? Using the scanf format %c, it captures from buffer…
-
2
votes1
answer725
viewsIs using %(limit)[ n] in scanf safe to capture strings?
I would like to know a totally safe way to capture strings without running the risk of buffer overflow or any other threat. I read a lot about ready-made functions and would like to know which ones…
-
2
votes1
answer102
views -
2
votes1
answer1026
viewsDoes the scanf record string on pointer that does not have a defined size?
I’m trying to understand how the strings in C. I noticed that even not defining in any part of the code any limit for the vector TextoUm[] (which follows in the code below), the function scanf can…
-
2
votes2
answers3142
viewsHow can I print the fifth part of a real number?
How could I print the fifth (index 4 from the dot) part of a real number without using libraries or a "complex" code for initial chapters. Make a program that reads a real number, and print the…
-
2
votes1
answer118
viewsType of char data needs space after quotation marks in the scanf
#include <stdio.h> #include <stdlib.h> void main(){ char elevador; int cod=0, a=0, b=0, c=0; while(cod == 0){ printf("\nElevador utilizado (a/b/c)? "); scanf("%c", &elevador);…
-
2
votes2
answers4454
viewsWhat is sscanf() and sprintf()?
What is the purpose of the sscanf() and the sprintf()?
-
2
votes3
answers548
viewsError using scanf("%[ n]") in sequence
#include <stdio.h> typedef struct person{ char name[100]; char address[100]; int age; } Person; int main() { Person pessoa; printf("Digite seu nome:\n"); scanf("%99[^\n]", pessoa.name);…
-
2
votes1
answer428
viewsRead a number starting with 0
I’m having trouble reading a number initialized with long long long long valid; scanf("%lli", &valid); Input: 025 The variable valid will have as content 21 and not 25 If I change %lli for %llu…
-
1
votes1
answer309
viewsI have a bug in the scanf
I have to read N lines with one of the following 3 formats: "P k": the letter P followed by k being k an integer number; "A k": the letter To followed by k being k an integer number; "Q": the letter…
-
1
votes2
answers5595
viewsHow do I validate input in c?
My problem is that I have to force the user to enter a whole value only, if he puts anything else (characters or decimals) I have to make him type again. I’ve already tried to validate scanf but it…
-
1
votes1
answer223
viewsProgram does not wait to read the received content
I’m creating a program that reads the student’s name, number of fouls, 3 grades and returns if the student has passed, flunked for foul or flunked for average, knowing that the foul limit is 15, the…
-
1
votes1
answer195
viewsScanning an entry by scanf does not walk in the string beyond the white space
I’m trying to make a program that reads a sentence and then capitalizes every initial of every word, if not already. The problem is that I type in a sentence but it only returns the first word,…
-
1
votes1
answer658
viewsIs the null character 0 automatically placed at the end of the string or not because I limited the scanf?
#include <stdio.h> #include <stdlib.h> int main(void) { char nome[20]; char sobrenome[20]; char nomeSobrenome[40]; printf("Insira seu nome e…
-
1
votes2
answers333
viewsSingle variable declaration for scanf
I already know how to declare a variable in the traditional way using the scanf(), but I’m thinking of a way that I can use fewer lines and make the code more organized (that’s what I tried with the…
-
1
votes2
answers132
viewsHow to analyze the input in the while condition?
I am learning C, and as the language in which I was "literate" is Python, I usually make associations to better assimilate. In Python, I can receive a direct value in the while condition. Ex.: while…
-
1
votes2
answers1023
viewsReading on the same line
I have a struct to define the type DATA. typedef struct data { int ano, mes, dia; }DATA; DATA nasc; Now, I will read this information from the user input. printf("Digite sua data de nascimento");…
-
1
votes1
answer53
viewsPower function returning incorrect values within the while loop
I have a function power that returns the value of a potentiation receiving the parameters n and p (n^p). Outside the loop while the function returns the correct values, but within the loop function…
-
1
votes2
answers47
viewsHow to stop receiving keystrokes?
This is a memory game and while the numbers are playing I want the user not to be able to type. **for (i=0;i<2;i++) //Exibe os números que estão no vetor numeros[] { printf ("%d\t", numeros[i]);…
-
1
votes0
answers47
viewsProblems with input and output in the C language in Visual Studio
Below I have a code simple in C, the problem is that if I leave as is it does not print the received name on the screen, but when I change the scanf_s for scanf it works normally. What would be the…
-
1
votes2
answers2198
viewsProgram Ignoring the Scanf
I need to create an algorithm as requested below, but every time I run the program it "skips" steps. For example: I want you to stay like this Product: "Potato" Sector: "Food" Quantity: "15" Price:…
-
1
votes1
answer78
viewsCalculator is not capturing the second number
I have a code that I wrote, it takes two numbers and sums, subtracts, multiplies and divides. However, when incrementing the questions in the code and then running it reads only the number of the…
-
0
votes1
answer719
viewsC print name with scanf
I have the following code, the problem is that it returns string2 as '(null)'. How do I fix? and why does this happen? #include <stdio.h> int main() { char *string; char *string2;…
-
0
votes2
answers1917
viewsHow to Show all elements of an array declared in a C struct?
In that code: #include <stdio.h> #include <stdlib.h> struct cadastro { char nome[50]; int idade; char rua[50]; int numero; }; int main() { struct cadastro c[4]; //Array[4] de estruturas…
-
0
votes1
answer3481
viewsFailure to read char with scanf ("%c")
Check this code to register two random matrices and then add, multiply... I want to put an option that every operation made the user has the option to quit the program, without going back to the…
-
0
votes1
answer268
viewsProblem with scanf in %d receiving a keyboard letter
I’m having a problem, I’m reading a int %d for scanf, but if the user type a letter the program enters loop. void chama_menu_switch(Fila **f, int n){ char confi; int i,y,x,a,z; double r; a = 0; int…
-
0
votes1
answer391
viewsValidation of scanf in c
I have a problem that I need to validate an entry to receive only integers, if I do not receive, I must force the user to enter an integer. I cannot disregard numbers after the comma (in the case of…
-
0
votes1
answer24
viewsReceive a user’s data and show that data at the end
I want to receive the input of a user and at the end I run the program I want to show them, but I think the variable address is not like that, because the program jumps from name to age directly,…
-
0
votes0
answers118
viewsSegmentation fault (core dumped) in matrix data scanf
This following piece of error code, does not read user data to allocate in 5x2 matrix, can not find the problem int linha=0, coluna=0; int matriz[5][2]; for(linha=0;linha < 5; linha++){…
-
0
votes1
answer353
viewsUse of Printf and Scanf in Eclipse and Netbeans - C Language
Good night. I have the program below that asks the user to enter 2 numbers and then present them. Code Blocks is working correctly, but when running in Eclipse or Netbeans, the system is waiting for…
-
0
votes1
answer624
viewsProblem with printf and scanf - My code does not print the correct information
I have this code here that is not reading the characters correctly when printing the data filled by the user on the screen. Can you help me?? //Question 1) Make an algorithm that reads a user’s…
-
0
votes2
answers87
viewsString scanf() time problem
I wanted a help in solving the problem of a string, because when you read the program automatically from as invalid option any option, so you do not use the option I chose. No if I’ve tried with…
-
0
votes1
answer123
viewsHow to make the program stop at each printf?
I would like to make the user type a printf() at a time, being the "Name, RG and Email" but as soon as I type the name, it executes everything else and ends the program, as I make it stop in the…
-
0
votes1
answer46
viewsHow to write two unsigned char variables in c
I’m having trouble writing two variables of type unsigned char using scanf, only the second value is saved in variable, I imagine it is buffer with garbage tried to treat and even so did not…
-
0
votes1
answer67
viewsProgram does not execute the While command after reading in the scanf
I was trying to make a program to calculate the mmc of two integer values, but I can’t even test my code, since no tested compiler has ever run , someone knows what might be?Follows the code:…
-
0
votes1
answer152
viewsProblem in returning Struct in C
I’m making a simple program in C that takes name, enrollment and two student grades but when returning the value typed struct in the function Show it does not return anything #include…
-
0
votes1
answer297
viewsC CHAR reading that works with %s but not with %c, why? And how does INCREMENT work on a pointer?
I hosted the code complete in the Pastebin: https://pastebin.com/feKaxAiz. It is a matrix where it is possible to perform the SUMMING UP or AVERAGE of the elements above the MAIN DIAGONAL. It is…
-
0
votes1
answer148
viewsInput treatment with scanf() return
I’m trying to write an input treatment in my C code in the excerpt where the n values of an array and are read. If there is an error in reading (if the input is a char for example), assign 885444751…