Below functions make sure we are safely and completely reading and writing from a file pointer fd, opened on a specific file.
getcwd, getwd, get_current_dir_name functions return a null-terminated string containing an absolute pathname that is the current working directory of the calling process. The pathname is returned as the function result and via the argument buf, if present.
Following program converts integer number 42 to string “42” using sprintf. sprintf() writes to the character string. We can compile this program is using gcc as, We can compile run program on command line as,
In C program, comments doesn’t have any use other than for better understanding of the developers of the source code in case you are writing big program and wants to remember what is the functionalities of the code blocks (functions/lines) in program. Single Line Comment — Any text on a single line after // is … Read more
In this post, we will create a simple C program, compile it with debugging enabled and then debug it using GDB debugger to identify where exactly the problem is occurring while the program is executing. To prepare our program for debugging with gdb, we must compile it with the -g flag. Now, we will start … Read more
This post is in continuation of our previous post “Understanding ARP (Address Resolution Protocol) basics“ To visualise what ARP reply we are getting from arping command, we need to write an ARP reply receiver code as below, compile this code as, So, as we can see “arping” sent above ARP reply to broadcast destination mac … Read more
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Following is an example to get the size of int type on any machine.
If you are trying to run modulo / remainder operator like below, there are higher chances you might get an error as “error: invalid operands to binary” The solution for this error is as mentioned below. Solution : The remainder operator (otherwise known as the modulo operator) % is a binary operator (i.e., takes exactly … Read more
The remainder operator (otherwise known as the modulo operator) % is a binary operator (i.e., takes exactly 2 operands) and operates only on integer types (e.g., short, int, long, long long, etc). Now, if we change the number from 6 to something else, for example 11, the output will be as below,
As we have seen in “C program for using modulo operator, finding if number is dividable and print remainder.” if we want to use modulo operator, we have to use either integer or typecast the value with “int” and result also was integer. Now, what if we have to do float operations and want to … Read more