Category Archives: C

File Handling in C

code:

 

Arguments from Command Line Console

code:

 

Problem 85: Product

Create a structure named Product with following two fields-

1. name (string)
2. price (double)

Then create a function named printProductInfo() which takes a parameter of Product type and print the information of that Product. Finally, in main function create a variable of structure Product named myProduct and call the printProductInfo() function passing myProduct as the parameter.
code:

 

Struct Problem 1: 101cproblems

Problem 81: Struct GPA

Create a simple structure named Student that holds the following variables-
i. id (integer)
ii. cgpa (float)
iii. name (string)
Now create an instance of that structure named s1 and scan the values from the user. Finally print the id, cgpa and name which user entered.

code:

Source:http://101cproblems.com/problem-81/

Another approach:

 

Typedef Enum Union Project

code:

 

Typedef Enum

code:

 

Another Good Example of Struct using Function and Pointer

code:

 

Using function with Struct user defined type also pointer

code:

why we used *sp in one place and sp in another place ?there s a reason behind this
*sp means address is passing where after the local input takeup it will go but if not use  dereferencing then it will not go outside. So to write we need with address.

and in sp it is read only. so to print sp is enough to show.

vid:

Use Pointer with Struct

code:

 

Typedef Alias to Use Type without Struct keyword

code:

using only the alias of typedef no other value:

 

Struct in C(User Defined Type)

code:

 

Array of String

theortecical concept source:
http://stackoverflow.com/questions/20347170/char-array-and-char-array

code:

Problem:
source: 101cproblems:

Problem 80: Array of String

Take an array of string named fruitNames and store four fruit names (“Mango”, “Jack-fruit”, “Banana”, “Litchi”). Now iterate the array using loop and print the names of the fruits each in a separate line.

code:

 

2d array dynamically with pointer/basics of 2d array

code:

with free:

vid:

 

Never Waste Your Memory, So use custom memory allocation with malloc() function and pointer to allocate memory dynamically, calloc(), realloc()

malloc() code:

calloc() code:

calloc vs malloc()

calloc initialized each byte with zero

realloc()
code:

 

theory vid:

Void Pointer and Typecasting in Pointer

code: