Category: Learn C Online

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;...

Program to Demonstrate Typecasting in C 4

Program to Demonstrate Typecasting in C

Here is a program to demonstrate typecasting in C programming language. #include #include void main(){ float result; int num1, num2; clrscr(); num1 = 10; num2 = 3; result = num1/num2; printf(“\nBefore Typecasting: %f”,result); /* As num1 and num2 are declared as int, it will return int value and it will get stored in the variable “result” as float i.e. 3.000000 To solve this problem we can use typecasting. */ result = (float)num1/num2; printf(“\nAfter Typecasting: %f”,result); getch(); } Output: Before Typecasting: 3.000000 After Typecasting: 3.333333

Program to check if a number is Armstrong or not 4

Program to check if a number is Armstrong or not

Definition (Armstrong Number): An n-digit number equal to the sum of the nth powers of its digits. Example: 153 = 13 + 53 + 33 1634 = 14 + 64 + 34 + 44 #include<stdio.h> #include<math.h> int main(){ long int num =153, count = 0, i, temp1, temp2, temp3 = 0; clrscr(); printf(“Enter the number: “); scanf(“%ld”,&num); if(num <= 0){ printf(“\nEnter the number greater than 0”); return 0; } temp1 = temp2 = num; while(temp1!=0){ temp1=temp1/10; count++; } for(i=0;i < count; i++) { temp3 = temp3 + pow((temp2%10),count); temp2 = temp2/10; } if(num == temp3) { printf(“\n %d is an...

String handling functions in C 22

String handling functions in C

In this article, you will understand different string handling functions in C. By the end of this article, you will learn how to write C programs to perform the following string operations –  find the length of a string, compare 2 strings, copy one string to another, concatenate 2 strings, etc. Following are some of the useful string handling functions in C. strlen() strcpy() strncpy() strcat() strncat() strcmp() strncmp() strcmpi() strncmpi() These string handling functions are defined in string.h header file. Hence you need to include this header file whenever you use these string handling functions in your C program....

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