Monday, 8 December 2014

c program to get ip address

#include<stdlib.h>

int main()
{
   system("C:\\Windows\\System32\\ipconfig");

   return 0;
}



ip address

C Program to Write to a Sentence to a File

#include <stdio.h>
#include <stdlib.h>  /* For exit() function */
int main()
{
   char c[1000];
   FILE *fptr;
   fptr=fopen("program.txt","w");
   if(fptr==NULL){
      printf("Error!");
      exit(1);
   }
   printf("Enter a sentence:\n");
   gets(c);
   fprintf(fptr,"%s",c);
   fclose(fptr);
   return 0;
}

Wednesday, 15 October 2014

Google announces Android 5.0 Lollipop



Google has just revealed that the next major version of Android, 5.0, will be known as Lollipop. After months of teasing the OS, the search giant is finally taking what was

Tuesday, 14 October 2014

Invention Story of Computer

Inventors have undoubtedly been heroes for all of us. By burning the midnight oil, they have gifted humankind with revolutionizing technology. Whether it is a mobile phone or a radio, they have never been miser in endowing the society with life transforming inventions. One such empowering invention has been ofComputer. Not one but there are many geniuses behind the development and growth of this phenomenal technology.

Illustrate the concept of unions

/* Write a  C program to illustrate the concept of unions*/
#include <stdio.h> #include <conio.h>

Illustrate the operations of single linked list

/* Write a C program to illustrate the operations of singly linked list */
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #define MAX 30

Implement stack and perform push, and pop operations

/* Write a C program to implement stack. Stack is a LIFO data strcuture    *
 * LIFO - Last in First Out                                                *
 * Perform PUSH(insert operation), POP(Delete operation) and Display stack */
#include <stdio.h> #include <conio.h> #define MAXSIZE 5

Saturday, 11 October 2014

Download Introduction to algorithms (cormen) free ebook

C program to check leap year (using if-elseif-else structure)

#include<stdio.h>
int main( void ){
     int year = 2012;
     if( year % 4 == 0 && year % 100 != 0 ) {
           printf("Leap Year..\n");
     }else if (year % 4 == 0 && year % 400 == 0 ){
           printf("Leap Year..\n");
     }else{
           printf("Not Leap Year..\n");
     }
     return 0;
}

C program to check leap year (using if-else and logical operator structure)

#include<stdio.h>
int main( void ){
int year = 2012;
if(( year % 4 == 0 && year % 100 != 0 ) || (year % 4 == 0 && year % 400 == 0 )){
      printf("Leap Year..\n");
}else{
      printf("Not Leap Year..\n");
}
return 0;
}

C Basic Syntax

You have seen a basic structure of C program, so it will be easy to understand other basic building blocks of the C programming language.
Tokens in C
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens:
printf("Hello, World! \n");
The individual tokens are:

C Operator Types

What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. C language supports following type of operators.
  • Arithmetic Operators
  • Logical (or Relational) Operators
  • Bitwise Operators
  • Assignment Operators
  • Various Other Operators
Let’s have a look on all operators one by one.

The complete reference C free download ebook

C Programming Strings






In C programming, array of character are called strings. A string is terminated by null character /0. For example:
"c string tutorial"
Here, "c string tutorial" is a string. When, compiler encounters strings, it appends null character at the end of string.
Memory diagram of strings in C programming

DECLARATION OF STRINGS

Strings are declared in C in similar manner as arrays. Only difference is that, strings are of chartype.
char s[5];
Declaration of strings in C language
Strings can also be declared using pointer

Online Compilers


There are many online compilers , but some good ones are:-




Dynamic Memory in C (malloc, calloc, realloc, free)

Let’s take a look at the four methods that allow us to utilize dynamic memory in C. Dynamic memory just means we are using memory on the heap, instead of on the stack.

Why would you want to use dynamic memory?

You might want to create a variable or object that persists beyond the scope of the function it is created in (i.e. to share it between functions). The only way to do this is to create it dynamically, and then remember to deallocate it at a later point. Alternatively, you might not know the size of something you are using until runtime (e.g. reading in a file), in which case the heap is a better place to store your data. Why? Because the size of the stack is limited and it may be too small for unknown data processed at runtime.

Wednesday, 8 October 2014

Inline Functions versus Macros

Although inline functions are similar to macros (because the function code is expanded at the point of the call at compile time), inline functions are parsed by the compiler, whereas macros are expanded by the preprocessor. As a result, there are several important differences:
  • Inline functions follow all the protocols of type safety enforced on normal functions.
  • Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
  • Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.

Example


The following example shows a macro that converts lowercase letters to uppercase:
// inline_functions_macro.c
#include <stdio.h>
#include <conio.h>

#define toupper(a) ((a) >= 'a' && ((a) <= 'z') ? ((a)-('a'-'A')):(a))

int main() {
   char ch;
   printf("Enter a character: ");
   ch = toupper( getc(stdin) );
   printf( "%c", ch );
}
Sample Input: xyz

Sample Output: Z
The intent of the expression toupper(getc(stdin)) is that a character should be read from the console device (stdin) and, if necessary, converted to uppercase.
Because of the implementation of the macro, getc is executed once to determine whether the character is greater than or equal to "a," and once to determine whether it is less than or equal to "z." If it is in that range, getc is executed again to convert the character to uppercase. This means the program waits for two or three characters when, ideally, it should wait for only one.
Inline functions remedy the problem previously described:
// inline_functions_inline.cpp
#include <stdio.h>
#include <conio.h>

inline char toupper( char a ) {
   return ((a >= 'a' && a <= 'z') ? a-('a'-'A') : a );
}

int main() {
   printf("Enter a character: ");
   char ch = toupper( getc(stdin) );
   printf( "%c", ch );
}
Sample Input: a

Sample Output: A

How to see expanded source code of c programs?

If for any reason , you are unable to debug a macro , then you should view the expanded code of the program to see how the macros are getting expanded.

if your source code is present in file " prg.c "  then expanded source code would be stored in " " prg.I "     .

Compilation and Execution Process of C Programs

The compilation and execution process of C can be divided in to multiple steps:
  • Preprocessing - Using a Preprocessor program to convert C source code in expanded source code. "#includes" and "#defines" statements will be processed and replaced actually source codes in this step.
  • Compilation - Using a Compiler program to convert C expanded source to assembly source code.
  • Assembly - Using a Assembler program to convert assembly source code to object code.
  • Linking - Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
  • Loading - Using a Loader program to load the executable code into CPU for execution.

History of C language

The C programming language was devised in the early 1970s by Dennis M. Ritchie an employee from Bell Labs (AT&T).
In the 1960s Ritchie worked, with several other employees of Bell Labs (AT&T), on a project called Multics. The goal of the project was to develop an operating system for a large computer that could be used by a thousand users. In 1969 AT&T (Bell Labs) withdrew from the project, because the project could not produce an economically useful system. So the employees of Bell Labs (AT&T) had to search for another project to work on (mainly Dennis M. Ritchie and Ken Thompson).