How do you pass a function as a parameter in C?

Declaration A prototype for a function which takes a function parameter looks like the following: This states that the parameter f will be a pointer to a function which has a void return type and which takes a single int parameter. The following function (print) is an example of a function which could be passed to func as a parameter because it is … Read more

expression must have integral type

I get that compilation error because of this line which intended to increase the pointer by 0x200 (to point to the next segment) I’v seen this but I didn’t use any illegal symbol! P.S. The initialization of the pointer:

What’s the difference between a file descriptor and file pointer?

A file descriptor is a low-level integer “handle” used to identify an opened file (or socket, or whatever) at the kernel level, in Linux and other Unix-like systems. You pass “naked” file descriptors to actual Unix calls, such as read(), write() and so on. A FILE pointer is a C standard library-level construct, used to represent a file. The FILE wraps the … Read more

C read file line by line

If your task is not to invent the line-by-line reading function, but just to read the file line-by-line, you may use a typical code snippet involving the getline() function (see the manual page here):

conflicting types error when compiling c program using gcc

If you don’t declare a function and it only appears after being called, it is automatically assumed to be int, so in your case, you didn’t declare before you call it in main, so the compiler assume there are functions which their prototypes are int my_print2 (char *); and int my_print2 (char *); and you can’t have two functions with … Read more

Categories C Tags ,