4
u/ptchinster Mar 12 '21
!picoftext
5
u/rtlcprogbot Mar 12 '21
For the love of fuck dont give us a picture of text.
I am a bot. Replying to me notifies nobody
2
u/Willsxyz Mar 13 '21
Maybe I am missing something, but I don’t see what the problem is. Is there a problem?
1
u/nerd4code Mar 13 '21
There’s no actual question here (photo of text?!) but there’s bogus stuff in the code.
Don’t just throw literals like 5 around; #define for the bounds of a, then use a countof macro for the for loop limit:
#define countof(arr)(sizeof(arr)/sizeof(*(arr)))This helps ensure things stay bound if you change them.
Prompts shouldn’t go to stdout; stdio can be redirected, so stderr is a better option if you can’t use POSIX isatty to make sure you’re not issuing demands to something inert like a file or FIFO.
Always check scanf’s return; no reason the outside world has to cooperate with your input demands, and scanf can be especially touchy. Failure means one or more array elements will be left undefined, and that tends to frob the rest of your input unless you flush carefully.
&a[i] is exactly a+i. An expression of array type T[] will decay to T * unless you make actual use of its arrayness via sizeof, unary &, GNU __alignof__ or __typeof__, C11 _Generic, and probably something else I’m forgetting.
So when you next take &a, you don’t get the decay, you get an expression of type int (*)[5], which is a pointer to the entire array at once (same representation, different type from just a decayed to int *). So no & in that line, should’ve been a warning there.
Don’t use %u to print a pointer; undefined behavior. Use %p and cast its argument to void * or some variant thereof, b/c pointers don’t get valuefucked like other printf args (properly: default promotion).
Always end text output to stderr and stdout with a newline (stupid UB case otherwise). You can use puts if you’re not formatting.


4
u/soniduino Mar 12 '21
Is that DOS????