Browsing all articles in sample programme
Feb
7
Comments Off

Implement Timeout for one function in C

Author saurabh    Category c, sample programme, Tips     Tags

Here i have one function which is listen mode. this function listing something which i got form some device.

Here when my function is in listen mode that time i want to create timeout. if i will not get any response from particular device than i want o exit from this function and have to notify.

if during this timeout period if i will get some date from something or some action would be performed than i have to continue with work and stop this timeout.
read more

Jan
28

Why variables can not be declared in a switch statement just after labels?

see this code

#include<stdio.h>
int main()
{
   int i=1;
   switch(i)
   {
       case 1: int x=10;
               printf(" x is %d",x);
       break;
    }
    return 0;
}

Do you think this code will compile? if yes then you need to read this post….

read more

Jan
5

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

read more

Jan
5

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?

read more

Nov
6

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

Sep
27

How post-increment & pre-increment both are evaluated in function argument?

While surfing internet i came to following scenario. The behavior of bellow’s function i can not understand .Can you know why this output comes ?

#include<stdio.h>
   int main() {
   int a=5;
   printf("%d %d %d",a++,a++,++a);
   return 0;
   } 

read more

Sep
26

Concept of Octal literal in C

One day while debugging  one code i got one interesting things ..let me explain you by bellow’s  example.

#include<stdio.h>
main()
{
int a=010;
printf("a is %d",a);
}

if you think output of this program will

“a  is  10″

then your are missing something….

read more

Sep
25

How to set, clear ,toggle and check a single bit in C?

As being an embedded software engineer i would really suggest you this tricks. ..!  In many  application you need to deal with this bit wise operation. Sometimes you know this all stuff very well but still some time it takes  time to construct this logic or some time you got some mistakes in it. so i suggest you to paste this on your desk until you paste this in your mind..!

To set a bit

Use the bitwise OR operator (|) to set a bit.

 number |= 1 << x; 

That will set bit x.

read more

Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

latest comments

Find us on Facebook

Top Authors

36 posts
saurabh
22 posts
10 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link