Author: learnconline

Demo on Structures in C 12

Demo on Structures in C

The Structure is a special type of C data type. A structure contains a number of data types grouped together. Structure in C allows multiple data types to be grouped together. The below mentioned program is to demonstrate structures in C Programming Language. #include #include void main(){ struct animal{ int age; char name[10]; char gender; }a[10]; int no,i; clrscr(); printf(“Enter the number of animals: “); scanf(“%d”,&no); for(i=0;i<no;i++){ printf(“\nEnter the age of animal %d: “, i+1); scanf(“%d”,&a[i].age); printf(“\nEnter the name of animal %d: “,i+1); scanf(“%s”,&a[i].name); printf(“\nEnter the gender(M/F) of animal %d: “,i+1); scanf(“%s”,&a[i].gender); } for(i=0;i<no;i++){ printf(“\n%d”,a[i].age); printf(“\t%s”,a[i].name); printf(“\t%c”,a[i].gender); } getch(); }...

Storage Classes in C Programming Language 45

Storage Classes in C Programming Language

A storage class in C is an attribute that tells us where the variable would be stored, what will be the initial value of the variable if no value is assigned to that variable, life time of the variable and scope of the variable. There are four storage classes in C: 1) Automatic storage class 2) Register storage class 3) Static storage class 4) External storage class Automatic storage class in C: The keyword used for Automatic storage class is ‘auto’. The variable declared as auto is stored in the memory. Default value of that variable is garbage value. Scope...

Pointer Operations Demo in C 12

Pointer Operations Demo in C

Here, we will demonstrate pointer operations in C programming. #include #include void main(){ int arr[5]={12,13,14,15,16}; int *ptrArr, *ptrArr1,i; clrscr(); ptrArr = arr; printf(“\nPrinting the first element of array: %d\n\n”,*ptrArr); /*Pointer variable can be increased. If added 1 to it, it will point to the next element of the same array*/ for(i=0;i<5;i++){ printf(“%d\t”, *ptrArr); ptrArr++; } printf(“\n\n”); /*Now the Pointer is pointing to a memory location that is not reserved so if you will print the value at pointer location it will print garbage and some times it show any RUN TIME error because C compiler will not check array boundaries*/...

sprintf function Demo 2

sprintf function Demo

Understand how sprintf function works in C programming language with the help of an example. Here we demonstrate sprintf function in C language. If you have any questions, do feel free to comment. #include #include void main(){ char *str; char *first=”Learn”, *second = “C”, *third=”Online”; clrscr(); sprintf(str,”%s%s%s.com is a great site”, first, second, third); printf(“%s”,str); getch(); } Output: LearnCOnline.com is a great site Also See: Explanation on sprintf function

sscanf function Demo 1

sscanf function Demo

Understand how sscanf function works in C programming language with the help of an example. Here we demonstrate sscanf function in C language. If you have any questions, do feel free to comment. #include<stdio.h> #include<conio.h> int main(){ char *str = “Learn C Online”; char *first, *second, *third; clrscr(); sscanf(str,”%s %s %s”, first, second, third); printf(“%s”,first); printf(“\n%s”,second); printf(“\n%s”,third); return 0; } Output: Learn C Online Also See: Explanation on sscanf function

sscanf and sprintf functions 19

sscanf and sprintf functions

sscanf() function is used to extract strings from the given string. Consider, char *str = “Learn C Online”; If we want to extract “Learn”, “C” and “Online” in a different variable then it can be done using sscanf function. Syntax: sscanf(characterArray, “Conversion specifier”, address of variables); This will extract the data from the character array according to the conversion specifier and store into the respective variables. sscanf() will read subsequent characters until a whitespace is found (whitespace characters are blank, newline and tab). Let us understand this using an example. char *str = “Learn C Online”; char *first, *second, *third;...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet