Hot answers tagged

3 votes
Accepted

Why is this program behaving unexpectedly?

The problem is with your scanf and the fact that you are telling it it will read an int but you give it a char. ASCII values may be represented by integers, but scanf can distinguish them. It checks ...
user avatar
  • 7,326
2 votes
Accepted

Using scanf to read into array

Per the manual page of scanf() A sequence of white-space characters (space, tab, newline, etc.; see isspace(3)). This directive matches any amount of white space, including none, in the ...
user avatar
  • 17.4k
2 votes
Accepted

Question of inputing an array of char

First in the struct definition, you are the declaring a pointer to a char (char*), so if you don't want to use GetString(), when you try to store something that is not a pointer on any of this ...
user avatar
  • 1,359
2 votes
Accepted

Difference between scanf and get_int

As you will discover later on during the course, get_int() is part of the cs50 library "cs50.h" which is not used in the real world, except in the course. To ease the apprenticeship, David ...
user avatar
  • 63
1 vote
Accepted

Type int in scanf

When in doubt or you are sure you have done something correct but still receive errors, you should always check the the CS50 Man Pages to see what it says. In this case, it says that scanf needs a ...
user avatar
1 vote

dynamically allocated memory for a node is changed without any dereferencing?

You are printing tree->right the first time and &tree->right) the second time. So those won't be the same, since the first is the address stored in your variable tree->right and the ...
user avatar
  • 18.3k
1 vote

pointers and scanf : when do I use &x, *x or just x?

I think you got it. scanf needs a memory address so it knows where to write to. Whenever you add & you get the memory address of what follows. But in case of strings, what we pass as a string ...
user avatar
  • 20.7k
1 vote
Accepted

inputing multiple value(variable)

It can be done, and in fact, will be done as part of some of the last psets. But since this is a teaching environment, and one of the things this class teaches is how to find out how research ...
user avatar
  • 63.1k
1 vote
Accepted

How does printf and scanf works behind the scene?

The source code for the GNU C standard library implementation of vprintf (which is called by printf) should indicate that it is not a simple operation with a single answer, however, understanding ...
user avatar
  • 2,625
1 vote
Accepted

Reject empty/blank user input

Use GetInt() from the cs50 library! GetInt(), as its name suggests, waits for an int input from the user and returns it. You may use like that: #include <cs50.h> #include <stdio.h> int ...
user avatar
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible