How to Compare 2 Character Arrays [duplicate]

but I read somewhere else that I couldnt do test[i] == test2[i] in C. That would be really painful to compare character-by-character like that. As you want to compare two character arrays (strings) here, you should use strcmp instead: Edit: There is no need to specify the size when you initialise the character arrays. This … Read more

Whats the difference between UInt8 and uint8_t

In C99 the available basic integer types (the ones without _t) were deemed insufficient, because their actual sizes may vary across different systems. So, the C99 standard includes definitions of several new integer types to enhance the portability of programs. The new types are especially useful in embedded environments. All of the new types are … Read more

meaning of &variable (passed to function)

func being some arbitrary user defined function It couldn’t be “arbitrary” – it must take a pointer to int or a void* in order for the call to be legal. This ampersand is the “take address” operator. It passes func the address of a, so that the func could, for example, modify it: If your … Read more

Usage of \b and \r in C

The characters will get send just like that to the underlying output device (in your case probably a terminal emulator). It is up to the terminal’s implementation then how those characters get actually displayed. For example, a bell (\a) could trigger a beep sound on some terminals, a flash of the screen on others, or … Read more

fgetc(stdin) in a loop is producing strange behaviour

Terminals tend to be line-buffered, meaning that stream contents are accessible on a line-by-line basis. So, when fgetc starts reading from STDIN, it’s reading a full line, which includes the newline character that ended that line. That’s the second character you’re reading. As for fflush, that’s for flushing output buffers, not input buffers. So, what … Read more

How do I check if a string contains a certain character?

By using strchr(), like this for example: Output: exclamationCheck = 1 If you are looking for a laconic one liner, then you could follow @melpomene’s approach: If you are not allowed to use methods from the C String Library, then, as @SomeProgrammerDude suggested, you could simply iterate over the string, and if any character is the … Read more