C program to find file properties using stat() function

Stat Linux

Stat() function in C is used to retrieve information about the file by accepting the filepath as an argument to it. Stat() function can help us to extract following information about any file using C program. File type and mode Number of hard links from the file User ID of file owner Group ID of … Read more

Functions in C

Function in C programming is a group of statements which are separated from main task for the purpose of calling it repeatedly, as and when required. A function normally does a predefined task and returns the result of operations to the statement from where this function is called. Functions greatly help to simplify the main … Read more

How executable is created during compilation on Linux ?

This code is tested on Ubuntu . You may need to twick the script if you use a different Linux version. The steps for compilation as as below, write a source code helloworld.c run a preprocessor which create helloworld.i run a compiler which creates helloworld.s by taking preprocessed file helloworld.i as input. run a assembler which … Read more

How to call Assembly function from C code ?

In this post, we use ARM are reference architecture for writing the assembly code but the basic way of accessing functions defined in assembly program from C should remain almost similar ( except instructions ) for other architectures. Q. Write a C program helloworld.c which would call a function “simpleAdd” defined in assembly code ? … Read more

How to implement linked list in C programming ?

This programs shows a simple way to implement singly link list ( Singly link list is the list which can be traversed only in one direction i.e. forward till end ) The above program is self explanatory which initialises the head element of the linked list, adds more nodes into the linked list, and at … Read more

How to implement stack in C programming ?

In continuation of demonstrating simple implementation of data structures, as we shown in our last post “How to implement linked list in C programming ?”, in this post we will show how you can implement simple stack in C programming language. Stack is nothing but a one this kept on another, where we define how … Read more

C program to calculate length of a String

strlen – calculate the length of a string If you are implementing some C program dealing with character string, its most likely that at some point of time, you need to know what is the total number of characters in this string. C’s provides a standard library function “strlen” to know this. As, we can … Read more

C program for creating a text file from string in buffer

Create a str_to_file.c file as contents below, OR use from github Compile above source as, Test / Execute it as, This will create myfile.txt in your current working directory where you have str_to_file binary, The code is also available at github Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google … Read more

Using electric fence for debugging memory leaks in Linux

Electric Fence helps you detect two common programming bugs: software that overruns the boundaries of a malloc() memory allocation, and software that touches a memory allocation that has been released by free(). Unlike other malloc() debuggers, Electric Fence will detect read accesses as well as writes, and it will pinpoint the exact instruction that causes an error. Create … Read more