Category Archives: C

File Handling in C

Fgets Code:

Fgetc Code:

Fscanf code:

 

Storage Class Specifier: IN C

Auto Example:

Output:
6
6
6
Static Example:

Output:
6
11
16
Register:

It will take short time as calculation happen in registers.
extern example:

 

Pointer Good Basic

It will clear the confusion about the pointer when arises.

Sum clear:

example code:

Array and Pointer:

Array is nothing but a pointer:

another variable pointer example:

 

Count number of 2’s in a given range (0 to n)? (ex: range between 0-20, Ans: 3 (i.e [2], 1[2], [2]0))

Google Search: https://www.google.com/search?q=Counting+2s&ie=utf-8&oe=utf-8&client=firefox-b#q=Counting+2s+in+c

SOlution: https://www.careercup.com/question?id=56794

 

Frequency of Digit in A Number

code:

Ref: http://www.codeforwin.in/2016/10/c-program-to-count-frequency-of-digits-in-number.html

Logic to Find First and Last Digit

Last Digit:

First Digit:

 

 

String Frequency Count

code:
simple code:

good output:

Reference: http://www.codeforwin.in/2015/04/c-program-to-calculate-the-frequency-of-each-character-in-a-line.html

101cproblems.com solution:

 

 

String Palindrome Problem

My Own Logic:

Another logic:

Simple:

another good logic:

 

 

Count word

Problem from 101cproblems.com:
Write a program which will take a sentence as input and tell us how many words are there. [If user gives input “I love Bangladesh”, then the output should be: 3]

code:

 

String Problem: Uppercase to Lowercase, Lowercase to Uppercase

Problem 70: Case Fix

You are given a string mixed with uppercase and lowercase letters . Your task is to write a program which will
flip the letters : (UpperCase -> LowerCase, LowerCase -> UpperCase)

Example:
INPUT:        OUTPUT:

eLepHanT   Elephant

cAt                  Cat

SuNDAY       Sunday

code:

not upto the output yet:

beautiful code with exacts output:

 

 

String Problem: ASCII table related

Problem: Write a program which takes a string of alphabet as input and replace all the characters with the 3rd immediate character of it. All the alphabets of the input string will be small letter. [If user gives input “abc” you should print “def”, if user gives input “xyz” you should print “abc”]

mycode:

 

Concatanated String Problems

Problem: Take three different string as input from the user(“We”, “ Love” and “ Bangladesh”). Now concate these three string and print it (“We Love Bangladesh”). [There is a leading space in “ Love” and “ Bangladesh”]

Code:

Another approach:

 

Reverse a string

Problem 65: Reverse
Take a word from user and print the word in reverse order. [If user gives  “BANGLADESH”, your program should print “HSEDALGNAB”]

code:

of another option:

 

String Refreshing

//Program to assign string and display the same

//specifiying the array string size

Assigning string character by character

//Read a string and display it

//It will not allow string

so we need gets(str)
code:

with gets we can print line with space: Zaki Live

//simple printf

//using puts

//putchar

Program to find length of a given string:

Using string related library function:

//string copy with out library function

//using strcpy library function

Concatenated String:

Using library function:

 

 

Array Self Input Size