Hot answers tagged

9 votes
Accepted

what is the difference beween atoi and (int)

Type casting using (int) would work predictably on a single char, although it would probably not give you the result you are expecting anyway. It does not give anything meaningful on a string. A ...
user avatar
3 votes
Accepted

pset3 duration itoa - with "&"

First, understand what strings in C are. Strings in C are pointers to a character, or char* (if you use type string, that's a custom alias for the same thing). The convention then says that the ...
user avatar
  • 20.7k
2 votes

atoi always returns 0

If this is for example for Caesar cipher and you're running ./caesar 2 then key should indeed be set to an integer of 2 as argv[0] is the program name and argv[1] is the string 2. But int atoi(...
user avatar
  • 264
1 vote

CS50-pset2-Validating the Key-how to check or reject the user's input is decimal or not

You are meant to reject any number of command-line arguments other than one (means argc should be 2). To test whether a given character is numeric/alphabetic, you can use the isdigit/isalpha function (...
user avatar
  • 20.7k
1 vote
Accepted

How to validate the key in caesar?

Is this due to where I am putting my atoi code? actually it's because you didn't read atoi's manual page. carefully, at least. the man page explicitly states that atoi does not detect errors which ...
user avatar
  • 17.4k

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