Questions tagged [scanf]
The scanf tag has no usage guidance.
12
questions
0
votes
1
answer
149
views
Difference between scanf and get_int
Suppose I want a user to enter an integer between 1 and 8.
To start with, here is the program that uses scanf to accept integer from user.
#include <stdio.h>
#include <cs50.h>
int main (...
0
votes
2
answers
49
views
Type int in scanf
#include <stdio.h>
#include <cs50.h>
int main (void)
{
int number;
scanf ("enter a number %i", number);
}
The above is perhaps a starter program. Still struck. Number is type ...
0
votes
1
answer
23
views
dynamically allocated memory for a node is changed without any dereferencing?
I am in week 5(data structures) and I tried to make a simple binary search tree.
then I tried to create a function for getting around on this tree!
this is a part of get_around function :
printf(&...
1
vote
2
answers
9k
views
pointers and scanf : when do I use &x, *x or just x?
The following code works but why do I have to use 'x' instead of '&x' inside scanf()?
```
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *x = malloc(sizeof(char) *...
0
votes
1
answer
24
views
Code won't progress unless user inputs a number
I was writing a binary search function before finishing lecture 3 because I wanted to do some practice on my own. I was using scanf, which I had looked up, as I wanted to learn how to code without the ...
0
votes
1
answer
998
views
Why this code leads to segmentation fault?
1) In CS50 ide, it does not even compile giving error: format specifies type
'int *' but the argument has type 'int' [-Werror,-Wformat]
scanf (" %d", array[n]);
2) In codeblocks, it runs ...
0
votes
1
answer
739
views
inputing multiple value(variable)
So I was thinking that instead of inputting
1
2
3
with enter at the end of each input.
which use{ scanf("%i",&a) in a loop}
I wish to to input somthing like
1 2 3
which uses { scanf("%i %i %i",&...
3
votes
2
answers
61
views
Why is this program behaving unexpectedly?
The program below prints a value of size 20 no matter how small input we provide. Why?
#include <stdio.h>
#define LENGTH 20
int main(){
int arr[LENGTH], size = 0;
printf("Enter array ...
0
votes
1
answer
95
views
Question of inputing an array of char
I created a struct, it's elements are all char*. When it comes to asking inputs for these char*, i don't want to use GetString(), instead i tried scanf(). The output is definitely wrong.
Here is my ...
2
votes
1
answer
2k
views
How does printf and scanf works behind the scene?
How do printf and scanf actually works behind the scene ??
0
votes
2
answers
148
views
Using scanf to read into array
#include <stdio.h>
int main(void)
{
int array[10] = {};
scanf("%d\n", array);
for (int i = 0; i < 10; i++)
{
printf("%i ", array[i]);
...
0
votes
1
answer
180
views
Reject empty/blank user input
For pset1 I want to reject an empty user input, so that when the user presses 'enter', either the Mario code runs or it gives the user an error message.
Pseudo code:
printf ('message to input 1-23'...