Wednesday, September 5, 2012

LIST.H AND FILEOPERATION.H

list.h file is simulates the operation of list similar to python and fileoperation.h can read file line by line and even split a line returning a list of all split items.
You can download from following links.

list.h
list.cpp

fileoperation.h
fileoperation.cpp

Suggestions are always welcomed.

Monday, December 27, 2010

C Program that prints a calendar.

#include<stdio.h>

int main()
{
int i,j,k,numOfDay,numOfDayCount,lastIndex=1;
char month[12][12]={
                "JANUARY",
                "FEBRUARY",
                "MARCH",
                "APRIL",
                "MAY",
                "JUNE",
                "JULY",
                "AUGUST",
                "SEPTEMBER",
                "OCTOBER",
                "NOVEMBER",
                "DECEMBER"
        };

for(k=1;k<=12;k++)
{
if(k%2==0)
numOfDay=30;
else
numOfDay=31;

if(k==2)
numOfDay=28;
if(k==4)
                        numOfDay=30;

printf("\n\t%s\n",month[k-1]);
          printf("  ---------------------------\n");
          printf("   S   M   T   W   T   F   S\n");
          printf("  ---------------------------\n");
numOfDayCount=1;
for(i=1;i<=5 && numOfDayCount<=numOfDay; i++)
{
for(j=1; j<=7; j++){
if(j<=lastIndex && lastIndex>1)
{
printf("%4c",' ');
}
                                     else
 {
if(numOfDayCount<=numOfDay){
printf("%4d",numOfDayCount++);
lastIndex=j;
}
                                       else
{
printf("%4c",' ');
}
}
}
if(lastIndex==7){
lastIndex=1;
}
printf("\n");
}
printf("\n\n");
}
return 0;
}

C Program of Indian Team using function.

#include<stdio.h>


void india(void);


int main()
{


printf("\nThis is a informative for the ICC Cricket top ranking team-'INDIA'.\n");

india();

return 0;
}

void india(void)
{
int player,choice;


printf("\nIndian team:\n\n");
printf("1.Gautam Gambhir\n2.Virender Sehwag\n3.Rahul Dravid\n4.Sachin Tendulkar\n5.Yuvraj Singh\n");
printf("6.Yusuf Pathan\n7.Irfan Pathan\n8.Harbhajan Singh\n9.Praveen Kumar\n10.Zaheer Khan\n");

start:
printf("\nPress 1 to select the players and 0 to Exit.\nYour choice: ");
scanf("%d",&choice);

switch(choice)
{
  case 0: printf("\nThank You!\n");
  break;

  case 1: 
printf("\nSelect Player: ");
scanf("%d",&player);

switch(player)
{
 case 1: printf("\nGAUTAM GHAMBHIR\n");
printf("\nCompetition Tests ODIs FC List A\nMatches 33 100 117 202\nRuns scored 2,825 3,351 9,830 6,690\nBatting average 51.36 38.07 54.91 36.75\n100s/50s 9/11 7/21 32/40 15/39\nTop score 206 150* 233* 150*\nBalls bowled 0 6 385 37\nWickets 0 7 1\nBowling average 39.57 36.00\n5 wickets in innings 0 0 0\n10 wickets in match 0 0 0\nBest bowling 0/13 3/12 1/7\nCatches/stumpings 27/– 30/– 76/– 60/–\n");
goto start;


case 2: printf("\nVIRENDER SEHWAG\n");
printf("\nCompetition Test ODI FC LA\nMatches 84 228 139 290\nRuns scored 7,550 7,380 11,178 9,035\nBatting average 54.71 34.64 50.57 33.96\n100s/50s 22/27 13/36 33/39 13/52\nTop score 319 146 319 146\nBalls bowled 3,249 4,230 7,416 5,716\nWickets 39 92 96 134\nBowling average 42.12 40.39 39.97 36.68\n5 wickets in innings 1 0 1 0\n10 wickets in match 0 n/a 0 n/a\nBest bowling 5/104 4/6 5/104 4/17\nCatches/stumpings 61/– 84/– 119/– 106/–\n");
goto start;

case 3: printf("\nRAHUL DRAVID\n");
printf("\nCompetition Test ODI FC LA\nMatches 147 339 278 444\nRuns scored 12,000 10,765 22,135 15,147\nBatting average 53.31 39.43 55.89 42.54\n100s/50s 31/59 12/82 62/113 21/111\nTop score 270 153 270 153\nBalls bowled 120 186 617 477\nWickets 1 4 5 4\nBowling average 39.00 42.50 54.60 105.25\n5 wickets in innings 0 0 0 0\n10 wickets in match 0 0 0 0\nBest bowling 1/18 2/43 2/16 2/43\nCatches/stumpings 199/0 196/14 340/1 233/17\n");
goto start;

case 4: printf("\nSACHIN TENDULKAR\n");
printf("\nCompetition Test ODI FC LA\nMatches 175 442 278 529\nRuns scored 14,513 17,594 23,406 21,150\nBatting average 56.91 45.12 59.86 45.87\n100s/50s 50/59 46/93 77/105 57/111\nTop score 248* 200* 248* 200*\nBalls bowled 4,078 8,020 7,443 10,196\nWickets 44 154 69 201\nBowling average 53.93 44.26 61.81 42.01\n5 wickets in innings 0 2 0 2\n10 wickets in match 0 n/a 0 n/a\nBest bowling 3/10 5/32 3/10 5/32\nCatches/stumpings 106/– 132/– 174/– 169/–\n");
goto start;


case 5: printf("\nYUVRAJ SINGH\n");
printf("\nCompetition Test ODIs FC List A\nMatches 33 250 89 317\nRuns scored 1,582 7,345 5,348 9,491\nBatting average 35.78 37.09 43.12 37.96\n100s/50s 3/8 12/43 16/25 16/56\nTop score 169 139 209 172\nBalls bowled 751 3,932 1,807 4,929\nWickets 8 82 19 114\nBowling average 53.87 40.88 51.36 36.45\n5 wickets in innings 0 0 0 0\n10 wickets in match 0 0 0 n0\nBest bowling 2/9 4/6 3/25 4/6\nCatches/stumpings 30/– 72/– 88/– 93/–\n");
goto start;


case 6: printf("\nYOUSUF PATHAN\n");
printf("\nCompetition ODIs FC List A T20I\nMatches 30 40 89 9\nRuns scored 247 1,997 1,792 122\nBatting average 20.58 35.03 30.37 24.40\n100s/50s 1/2 4/10 3/9 0/0\nTop score 123* 183 148 33*\nBalls bowled 668 7,161 3,055 89\nWickets 17 96 64 4\nBowling average 37.64 33.98 40.26 29.50\n5 wickets in innings 0 7 2 0\n10 wickets in match n/a 1 n/a n/a\nBest bowling 3/49 6/47 5/52 2/23\nCatches/stumpings 7/– 43/– 36/– 5/–\n");
goto start;

case 7: printf("\nIRFAN PATHAN\n");
printf("\nompetition Test ODI FC List A\nMatches 29 107 87 152\nRuns scored 1,105 1,368 2,946 1,870\nBatting average 31.57 22.80 31.01 22.53\n100s/50s 1/6 0/5 2/18 0/7\nTop score 102 83 111* 83\nBalls bowled 5,884 5,194 16,348 7,471\nWickets 100 152 301 220\nBowling average 32.26 29.90 28.99 28.67\n5 wickets in innings 7 1 14 1\n10 wickets in match 2 n/a 3 n/a\nBest bowling 7/59 5/27 7/35 5/27\nCatches/stumpings 8/– 18/– 26/– 27/–");
goto start;

case 8: printf("\nHARBHAJAN SINGH\n");
printf("\nCompetition Test ODIs FC List A\nMatches 88 212 152 262\nRuns scored 1,785 1,083 3,193 1,425\nBatting average 17.50 13.20 19.23 13.57\n100s/50s 2/8 0/0 1/12 0/0\nTop score 115 49 115 49\nBalls bowled 25,002 11,075 38,941 13,567\nWickets 369 242 646 310\nBowling average 31.88 32.84 28.30 31.16\n5 wickets in innings 24 3 38 3\n10 wickets in match 5 0 7 0\nBest bowling 8/84 5/31 8/84 5/31\nCatches/stumpings 41/– 60/– 74/– 79/–\n");         goto start;

case 9: printf("\nPRAVEEN KUMAR\n");
printf("\nCompetition ODI FC List A T20\nMatches 34 37 85 35\nRuns scored 201 1,387 1,201 290\nBatting average 16.75 25.21 22.66 15.26\n100s/50s 0/1 0/8 0/5 0/1\nTop score 54* 98 64 76*\nBalls bowled 1,646 7,840 4,226 742\nWickets 40 166 126 35\nBowling average 35.17 23.18 25.85 27.47\n5 wickets in innings 0 12 2 0\n10 wickets in match n/a 1 n/a n/a\nBest bowling 4/31 8/68 5/32 3/23\nCatches/stumpings 8/– 6/– 16/– 5/–\n");
goto start;

case 10: printf("\nZAHEER KHAN\n");
printf("\nCompetition Test ODIs FC List A\nMatches 72 175 136 223\nRuns scored 969 719 2,003 958\nBatting average 13.45 13.07 14.41 12.94\n100s/50s 0/3 0/0 0/4 0/0\nTop score 75 34* 75 42\nBalls bowled 14,417 8,577 27,899 11,165\nWickets 250 241 561 312\nBowling average 32.98 29.93 27.63 29.31\n5 wickets in innings 9 1 31 1\n10 wickets in match 1 n/a 8 n/a\nBest bowling 7/87 5/42 9/138 5/42\nCatches/stumpings 18/– 35/– 42/– 49/–\n");
goto start;


default: printf("Invalid selection. Please enter the correct no.!\n");
goto start;
}


     default: printf("Invalid selection. Please enter the correct no.!\n");
                 goto start;


}
}