How can i detect Windows or Linux in C,C++ programming?
Sometimes we need to write platform independent code which works in windows and linux machine without giving any flag or any modification in code or make file manually.
So in such case i usually use compiler generated macro to check the platform .
In Linux all c and c++ compiler define macro like linux
, In Windows all c and c++ compiler define macro like _WIN32
so we can use this macro to separate code for linux and windows see belows example code
How can I get what my main function has returned in Linux?
In a C program if we want to give some input from terminal then we can give it by:
int main(int argc, char *argv[])
In the same way, if we want to get return value of main() function then how can we get it?
In each main() we write return 1 or return 0; how can we know what my main() has returned at terminal?
Most common directory layout seen in all C/C++ based Project/Package/Library
I have been with lots of projects package or library written in C or C++ programming language has One common directory layout. So if you planning to design any new package /project/library in C or C++ programming language then this will really help you to design directory layout of your project.
Online C programming test | C programming Interview Questions and Answers
While surfing net i got one site which has excellent for doing Online c programming test. All Question are also divided by section vise like pointers, structures,functions..
Link: IndiaBix
Why fopen() doesn’t get fail by passing directory name in argument?
Once i have made one small application where i was passing full file name as command line argument in my application where i am going to fopen() that file BUT once i have just passed any directory name instad of file name still my fopen() does not get fails…!!
#include<stdio.h> #include <errno.h> int main() { errno = 0; FILE *fb = fopen("/home/jeegar/","r"); if(fb==NULL) printf("its null"); else printf("working"); printf("Error %d \n", errno); }
output is
workingError 0
here fb is not going null and also not getting any error..
Whats is difference between file descriptor and file pointer?
After having 1 year of experience in c programming when someone has asked this to me i was surprised that why i dont know this…!!
Well when i will going to interview someone in someday this would be my 1st question to him/her…!!!
File Descriptor :
“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.”
int fd; fd = open(path, O_CREAT | O_RDONLY, 0644); close(fd);
This way you are using that is file-descriptor. In short, file-descriptor is
- Low/Kernel level handler
- passe to read() and write() of UNIX System Calls
- Doesn’t include buffering and such features
- Less portable and lacks efficiency
- It’s some what OS specific so its not part of standard c programming language.
How can i use GCC in windows/cmd just like using gcc in linux terminal?
At work i use gcc in linux but at home i use windows so i need to figure out the way of using gcc in cmd of windows just like using gcc in linux terminal. Since i dont like to use IDE such eclipse and neatbeans.
i came to know three option
1> Use Cygwin package
2> Use MinGW
3> Use MSYS
Well among all of them i have chosen option of using Cygwin package because
- Cygwin is a collection of tools which provide a Linux look and feel environment for Windows.
- a DLL (cygwin1.dll) which acts as a Linux API layer providing substantial Linux API functionality.
Steps to install and configure cygwin :
Equivalent to getch() & getche() in Linux
Once in one situation i need to use getch() and getche() function in Linux based application so i have searched a lot for Equivalent header file for conio.h in Linux,But i came to know there is not any header file/library equivalent to conio.h in linux.
I want to make a switch case base menu where the user will give his option just by pressing one key & process should be moved ahead. I don’t want to let user to press ENTER after pressing his choice.
Somebody has suggest me very magical code for getch() and getche() function for linux which is i am sharing here. read more
Huffman Encoding Using Linked List with Source Code
After a long time, I am back. Months without programming and then finally I got some time on my hands. So I set out to code the Huffman’s Data Compression Algorithm. And the result is here!
The code is well-commented and I hav given some additional documentation. Also, I hav tested it extensively – right from small words to complete bollywood Songs..:P
Here i had did two types of Huffman Encoding
1 ) Simple User Input
2) Take Input from File
But if there are any probs,let me know.
Implementation limitation of c programming language
One day i thought ,
“What is the maximum number of arguments we can pass to a function in C ?”
i have searched some stuff and found following things.
As per International Standard of c programming language, an implementation translates C source files and executes C programs in two dataprocessing-system environments, which will be called the translation environment and
the execution environment.
As per logicaly we can pass infinite number of aguments to the function but the Limitation of such data processing-system environment makes following limitation to the implementation of c programming language .
From : C language standard n1256
5.2.4.1 Translation limits
Search in this website
our sponsors
latest comments
- Motasim billah on List of all standard version of c language
- kamal9211 on Top/Best C/C++ IDE for Windows & Linux
- kamlesh khot on Structure of a C-Program in Memory | How Heap,Stack,Data and Code segments are stored in memory?
- neha on List of all standard version of c language
- vamsi on List of all standard version of c language
Find us on Facebook
Top Authors
Find us on stackoverflow
Polls
My Bookmarks
- Audio/video Recorder & player application based on MATLAB
- check dependency of your binary
- defination of all standard c programming language function
- Great Question-Answer on c programming
- know what your c code means
- Limition of c programming language
- List of all version of c programming language
- Online c compiler
- php freelancing work
- some more stuff on C programming language
- Volatile Keyword in Embedded System
- Write Android application in c language