Posts

Program to find a word in a file and display all its position

  # include   <stdio.h> # include <string.h> int main ( ) { char wrd [ 256 ] , buffer [ 256 ] ; int n , m , i , j , line ; FILE * fp ; fp = fopen ( "text.txt" , "r" ) ; // open file printf ( "Enter the word you want to search in the file: " ) ; gets ( wrd ) ; m = strlen ( wrd ) ; // length of input word printf ( "All positions of word \"%s\" in the file\n" , wrd ) ; line = 0 ; // the following loop the file fp line by line // each line is stored in buffer while ( fgets ( buffer , 256 , fp ) != NULL ) { i = 0 ; n = strlen ( buffer ) ; // the followinf loop find position of the input word in the current line and // print the position of the word on the screen // the loop basically reads each word of the file and compare it with the input word while ( i < n ) { // comparing current word with input word j = 0 ; while

VARIABLES IN C LANGUAGE

Image
  Variables in C BY  CHAITANYA SINGH  |  FILED UNDER:  C-PROGRAMMING A variable represents a memory location that stores the data.  For example: an int variable num has a value 10 (int num = 10), here the variable name is  "num"  that represents the location in the memory where this value  10  is stored. As the name suggests, the  value of a variable can be changed any number of times . Syntax – Declaring a variable data_type variable name ; For example: //a variable num of int type int num ; //two variable ch1 and ch2 of char type char ch1 , ch2 ; //three variable x, y and z of float type where y has been // initialized with a value and other variables x & z are // un-initialized. Float x , y = 10.5 , z ; Example: Variables in C #include <stdio.h> int main () { int num1 = 20 , num2 = 50 ; char ch = 'A' ; float x = 10.5 , y = 13.5 ; printf ( "Variable 'ch' value: %c\n" , ch ); printf ( "

DATA TYPES IN C

  Data Types in C BY  CHAITANYA SINGH  |  FILED UNDER:  C-PROGRAMMING Data type specifies which type of data can be stored in a variable . For example, an  int  variable store integer value,  char  variable store characters,  float  variable store float value etc. These int, char and float keywords are data types that basically defines the type of data. In this guide, you will learn about  data types in C language with examples . The reason why we specify the data type of variable while declaring it, so that compiler know which type of data this variable can accept. Types of Data Types in C 1.  Primary data type 2.  Derived data type:  Array, pointers, struct, and union are the derived data types in C. We will discuss these in separate tutorials. 3.  Enumerated data type:  User defined data type, declared using enum keyword. 4.  Void data type:  Mostly used as a return type of function that does not return anything. 5.  Boolean data type:  Represents variables that can store either tru

FEATURES OF C LANGUAGE

  Features of C language 1. Simple C language is simple and easy to learn. The syntax of C is simple and gives flexibility to the programmer with its wide variety of in-built functions and data types. 2. Portable C is a machine independent language, which means a C program written one machine can run on another machine without requiring a code change. 3. Fast C is a compiler based language. C is power packed with several features but it is not bloated like some other programming languages, it supports only useful features which makes the  compilation of C file fast . 4. Extensible C program supports code modifications and addition of new code to the already existing programs, this makes C language extensible. It becomes  easier to add new functionalities to the existing C programs . 5. Rich libraries: C libraries are full of useful in-built functions. These functions can be used frequently to perform some repeated tasks. As a C programmer, you won’t need to write same code again and ag

HISTORY OF C LANGUAGE

  History of C Language BY  CHAITANYA SINGH  |  FILED UNDER:  C-PROGRAMMING C is a general purpose computer programming language . A general purpose language is a language that is widely used in various domains and not specific to a particular domain.  C programming language was created in 1972 by Dennis Ritchie at AT&T bell laboratories in U.S.A. Founder: Dennis Ritchie is known as the founder of C programming language. Early developments: Ken Thompson wanted to develop a Fortran compiler but later gave up on that idea and shifted his focus to develop an advanced version of BCPL system programming language. He made modifications in the syntax and made it much simple, he named this language as ‘B programming language’. In 1971, Dennis Ritchie started to improve the features of B language,  by 1972 he was able to write a new modified compiler which he renamed to ‘C’.  C language is a successor of ‘B programming language’. The B programming language didn’t gain as much popularity as

Introduction to C

  Introduction to C C is a very popular programming language because of the features it offers. Here are some of the features of C programming language. 1. Simple C language is simple and easy to learn. 2. Portable C is a machine independent language, which means a C program written one machine can run on another machine without requiring a code change. 3. Fast C is a compiler based language and it supports only useful features which makes the compilation of C file fast. 4. Extensible C program supports code modifications and addition of new code to the already existing programs, this makes C language extensible. It becomes easier to add new functionalities to the existing C programs. 5. Mid level programming language C language provides the benefits of high level and low-level languages both. C allows manipulation of hardware just like low level language and allows high user end functionalities like high-level languages. A simple C Program #include <stdio.h> int main () {