Hot answers tagged

5

INT_MAX is defined in limits.h, which is a standard C header. INT_MAX: Maximum value for an object of type int (32767 or greater) You may wonder why find.c needs that? int straw = GetInt(); if (straw = INT_MAX) If you look at cs50.c (which defines GetInt()), you'll see that GetInt() returns INT_MAX when it doesn't receive an integer: // get ...


4

The size of an int is dependent on the hardware and operating system environment that you are working with. It has historically had a lot to do with the type of processor in the system. Early computers had 8 bit, or 1 byte processors, which had integers as small as 1 byte - a real nuisance since that had a range of roughly +/- 127. Later, the 16 bit or 2-...


3

The question is hinting at you to think about why the array is initialized with a size of 12.


2

Assuming you don't want to add them and store the result in a new variable. To print them concatenated to each other like 15, you may write something like this. printf("%d%d\n", x, y); To add them and store the result in a new variable, you may multiply x by 10 first, then add them and store the result in a new int variable int sum = (x * 10) + y; printf("...


2

The code seems far more complicated than necessary, but this seems to be because you're trying to handle the imprecise float storage problem unsuccessfully. This can be resolved by simply converting dollars and cents in a float to cents only and storing it in an int. It's not that hard. First, remember that round functions round the input to the nearest ...


1

The reason is that if the code is doing division with all integers, it will do integer division, not normal division. Integer division will truncate the fractional part of the division. So, if the result were something like 3.8, the result would be truncated to 3. This would lead to a lot of errors in an entire image. Now, you can reduce the extent of ...


1

Simply put, the file integer, the executable file, doesn't exist. Only the source code file integer.c exists. You need to make integer first, in order to compile the source code and produce the executable file integer. THEN, you can run it with the command ./integer. If this answers your question, please click on the check mark to accept. Let's keep up on ...


1

I assume the % strlen(key) is causing some type conversion. Your logic is wrong. First iterate the key to ensure all characters are alphabetic, and maybe also uppercase the key there if you want. Then, after the first loop, iterate the plaintext, keeping a separate index for the key that you increment on encrypting a letter only. Separate loops. toupper(key[...


1

get_int() has no knowledge of the "2nd argument from generate.c". Remember from the spec: You’ll be prompted to provide some hay (i.e., some integers), one "straw" at a time. As soon as you tire of providing integers, hit ctrl-d to send the program an EOF (end-of-file) character. That character will compel get_int from the CS50 Library to return INT_MAX, ...


1

This is because when a/b is performed the result is o form int type which is 0 since the .625 part of the result is gone due to the expression a/b being an int. When the value a/b (i.e 0) is assigned to float x it stores a value 0 as floating point number 0.000 and displays that. You can try the following line ( float x = (float) a / b ;)


1

i = 32768; No reason at all why this wouldn't work. First, the size of int is 2^32 at the appliance, not 2^16. Second, even if you enter a higher value, it will never segfault. It will wrap around and go "back". ia = "0, 1, 2, 3, 4, 5" Not sure what you're trying to do there. First, you can't assign an array except upon initialization, that's valid for ...


1

quoting the C99 standard (6.5.3.4 - 20): C89, like K&R, defined the result of the sizeof operator to be a constant of an unsigned integer type. Common implementations, and common usage, have often assumed that the resulting type is int. Old code that depends on this behavior has never been portable to implementations that define the result to ...


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