Questions tagged [scanf]

The tag has no usage guidance.

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

Read any format of input with scanf?

How do I read any line that the user enters into scanf? I want to be able to do a full line where a space counts as a character of that line.
0
votes
1answer
5k 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
1answer
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
1answer
897 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
1answer
717 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
2answers
59 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
1answer
94 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
1answer
2k views

How does printf and scanf works behind the scene?

How do printf and scanf actually works behind the scene ??
0
votes
2answers
77 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
1answer
168 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'...