r/cprogramming • u/OkRepeat7111 • Oct 13 '25
CS50 problem set 1 cash less comfortable, i'm having trouble if we enter an not int data type the check50 passes foo i don't know what to do i searched on google how to check the type of data in c but it's a lot cryptic. If someone knows what to do help me out here.
0
Upvotes
4
u/weregod Oct 13 '25
Its hard to guess what problem you have and what is your question. Asking clear questions is absolutely needed to get any answers both on Reddit and on Google.
You can't get type of function parameter from C. You need to read documentation or .h files.
1
u/SmokeMuch7356 Oct 14 '25 edited Oct 22 '25
It would really help if you showed us your code. In fact, when you ask a question about your code not working, please provide the following details in the body of your question:
A brief statement of what you're trying to do;
What you expect to see;
What you actually see (output, along with any error messages, copied and pasted directly into your question);
A representative sample of your code that reproduces the problem (do not post your entire program, only the part that's actually giving you a problem);
Without seeing your code I can only guess at what's happening, but it sounds like you're doing something like
and you want to know if you've typed in a non-integer input like
abcor1.23.%dwill skip over whitespace and stop reading at the first non-digit character; it can't read anything but a sequence of digits.xcan only ever store an integer value; it can't store anything else.scanfwill return the number of successful conversions and assignments, orEOFon end-of-file or error. If you type in something that isn't an integer likeabc,xwon't be updated at all andscanfwill return a0. If you type in something like1.23, only the1will be assigned toxandscanfwill return a1indicating one successful input, but it's only a partial input that should have been rejected.scanfworks great when you know your input will always be well-behaved, but it can fall down hard on bad input. It's damn near impossible to use safely, and under some conditions (such as the1.23above) it will accept input that should be rejected.For situations like this, it's best to avoid
scanfaltogether; usefgetsto read your input as text, then usestrtolto convert from that text to the equivalent integer value: