Questions tagged as 'scanf'

2
answers

What is the best to use, scanf or get_s? in c

Having the name 'Maria da silva' as an example: scanf() will just read Maria, get_s() will read it all, correct? I am in doubt about the best one to use, my college professor says that we should clean the buffer for scan...
asked by 28.08.2018 / 21:16
1
answer

How to let the string size be set by scanf ()?

My question is about theory. I know it's possible to do a string without limiting its size as: char teste[] = "Teste"; However, I would like to know if you can do the same thing, that is, not limiting the size, but without saying what...
asked by 23.08.2017 / 19:37
1
answer

Construct an array through a vector

I put nine digits in the vector but my array comes out with random numbers, I would like my array to come out with the numbers that are in the vector below below my code: #include <stdio.h> #include <locale.h> int vetor [9]; int m...
asked by 07.06.2016 / 23:39
1
answer

Read a number starting with 0

I'm having problems 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 f...
asked by 24.08.2018 / 15:55
1
answer

char data type needs space after quotation marks in 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); switch(elevador){ case 'a...
asked by 19.06.2017 / 05:59
1
answer

The scanf writes string to a pointer that does not have a defined size?

I'm trying to understand how strings work in C. I noticed that even though I can not define any limit for the TextoUm[] (which follows in the code below) in any part of the code, % can write a string to that vector correctly. But the...
asked by 30.11.2016 / 23:24
1
answer

How to read a line in C

How to read a row of integers and store in a dynamic-sized vector? I currently read the string as a string (though the input is only integer) using gets, the only way that worked. The code looks like this: type def struct{char entrad...
asked by 12.08.2014 / 19:43
1
answer

Use% (limit) [^ \ n] in scanf is it safe to capture strings?

I'd like to know a totally secure way of capturing strings without running buffer overflow or any other threat. I read a lot about ready-made functions and would like to know which are the most recommended, but I wanted to be able to impleme...
asked by 07.11.2014 / 14:01
1
answer

How 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 opening chapters. Make a program that reads a real number, and print the fifth part of that number.
asked by 13.10.2017 / 14:00
1
answer

How does the buffer work using printf and scanf?

Using 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 scanf with the format %c , it captures the character-to-character buf...
asked by 07.11.2014 / 13:48