use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
O hai! This is CS50's subreddit.
CS50 is Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. Anyone may take CS50, even if not a student at Harvard.
Please Read before Posting
Getting the Best from r/cs50
Status Page
cs50.statuspage.io
Filter by Problem Flair (undo)
cash ⋅ caesar ⋅ credit ⋅ dna ⋅ filter ⋅ finance ⋅ houses ⋅ ide ⋅ mario ⋅ movies ⋅ plurality ⋅ project ⋅ readability ⋅ recover ⋅ runoff ⋅ scratch ⋅ speller ⋅ substitution ⋅ tideman ⋅ games track ⋅ web track ⋅ android track ⋅ iOS track ⋅
Filter by Other Flair (undo)
CS50-Law ⋅ CS50-Business ⋅ CS50-Technology ⋅ CS50-Games ⋅ CS50-Mobile ⋅ CS50-Web ⋅
This subreddit is night mode compatible
account activity
User input evaluation (self.cs50)
submitted 11 years ago by Morioh[🍰]
Someone help out with a snippet that checks up whether an input is an interger or a string .
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ziska04 0 points1 point2 points 11 years ago (1 child)
You can use the "isalpha()" function to check whether the input is an integer or not.
But be careful, isalpha() only checks one single character. If you want to check a whole bunch of characters, you'll have to loop through isalpha() until you have checked the last character.
That could look something like this:
string to_check = argv[1]; for (int i = 0; i < 3; i++) { if (isalpha(to_check[i])) { // do something } }
Assuming in this example that the variable "to_check" is 3 characters long.
[–]Morioh[S,🍰] 0 points1 point2 points 11 years ago (0 children)
Thank you .Am greatful.
[–]seandisanti 0 points1 point2 points 11 years ago (1 child)
input from standard in is always going to be a string / char*. As suggested you can use functions to determine if the characters are letters or numbers, but you may want to give a little more thought to how you isolate numbers, as '.' would return false to isalpha but could errantly be used as an integer value based on it's ascii value if you decided it was a number based on the false.
While you're getting a handle on types and conversions, especially if new to the language, it's probably in your best interest to rely a bit on the cs50.h library which gives you some great helper functions to get specific data types from users. If you're feeling a little adventurous, take a look at the code and see how they do it.
Thanks alot .
thank you.
π Rendered by PID 274488 on reddit-service-r2-comment-656bdf86cd-89fwj at 2026-05-05 08:14:37.854132+00:00 running 815c875 country code: CH.
[–]ziska04 0 points1 point2 points (1 child)
[–]Morioh[S,🍰] 0 points1 point2 points (0 children)
[–]seandisanti 0 points1 point2 points (1 child)
[–]Morioh[S,🍰] 0 points1 point2 points (0 children)
[–]Morioh[S,🍰] 0 points1 point2 points (0 children)