C++ – include unistd.h: why not cunistd?

Your algorithm is correct for most (all?) standard C headers, but unistd.h is not part of standard C so standard C++ in turn doesn’t include it with the other c… headers.

Read and write to binary files in C?

Does anyone have an example of code that can write to a binary file. And also code that can read a binary file and output to screen. Looking at examples I can write to a file ok But when I try to read from a file it is not outputting correctly.

Scanning Multiple inputs from one line using scanf

You have your printing loop inside your reading loop. It is trying to print out all of the trip information after reading the first one in. Edit: The trouble here is that the way scanf handles single characters is kinda unintuitive next to the way it handles strings and numbers. It reads the very next … Read more

How to convert const char* to char* in C?

To be safe you don’t break stuff (for example when these strings are changed in your code or further up), or crash you program (in case the returned string was literal for example like “hello I’m a literal string” and you start to edit it), make a copy of the returned string. You could use … Read more

How does one represent the empty char?

You can use c[i]= ‘\0’ or simply c[i] = (char) 0. The null/empty char is simply a value of zero, but can also be represented as a character with an escaped zero.

Categories C Tags

Makefile:1: *** missing separator. Stop

It’s a tabs problem. Some text editors may replace tabs with white spaces, make sure you use a proper text editor that doesn’t mess it up. Open your makefile in vi or any other rudimentary editor, and rewrite that makefile. Note that after each target rule, one single tab must be placed in the beginning … Read more

What is the difference between char array and char pointer in C?

char* and char[] are different types, but it’s not immediately apparent in all cases. This is because arrays decay into pointers, meaning that if an expression of type char[] is provided where one of type char* is expected, the compiler automatically converts the array into a pointer to its first element. Your example function printSomething … Read more