C Programming Links

  1. If you are looking for C++ Programming Tutorial Sites than visits following links
  2. EasyTutor.2ya.com: To Get huge collection of C, C++, Java, VB, Data Structure, Graphics :: SourceCode, article, links, video, faq :: Logon to www.EasyTutor.2ya.com
  3. Muhammad Tashir Shahzad: If you are student and looking a source-codes to complete your assignments, or interested in c/c++/assembly/vb/java codes... than you will find plenty of codes to clear you fundas... go for it http://www.mts-home.cjb.net/
  4. C Programming dot Com: It also provide you with tutorials for cprogramming and conceptual help. http://www.cprogramming.com
  5. Planet-Source-Code.com (PSC): If you are looking for specific source-code...than log-on to this website it provides you and user friendly search environment to search and locate your required source-code...note their are plenty of source-code available on this website the thing is that you should know how to apply search and get your required source-code. http://www.planet-source-code.com/
  6. ProgrammersHeaven.com: This website is similar to PSC, here you will find some nice source-code...as it is efficiently maintained and update @ regular interval of time by the web-master. http://ProgrammersHeaven.com



FAQ : C Programming

Interview Questions for C Programming

1. What does static variable mean?
2. What is a pointer?
3. What is a structure?
4. What are the differences between structures and arrays?
5. In header files whether functions are declared or defined?
6. What are the differences between malloc() and calloc()?
7. What are macros? what are its advantages and disadvantages?
8. Difference between pass by reference and pass by value?
9. What is static identifier?
10. Where are the auto variables stored?
11. Where do global, static, local, register variables, free
memory and C Program instructions get stored?
12. Difference between arrays and linked list?
13. What are enumerations?
14. Describe about storage allocation and scope of global,
extern, static, local and register variables?
15. What are register variables? What are the advantages of using
register variables?
16. What is the use of typedef?
17. Can we specify variable field width in a scanf() format
string? If possible how?
18. Out of fgets() and gets() which function is safe to use and
why?
19. Difference between strdup and strcpy?
20. What is recursion?
21. Differentiate between a for loop and a while loop? What are
it uses?
22. What are the different storage classes in C?
23. Write down the equivalent pointer _expression for referring
the same element a[i][j][k][l]?
24. What is difference between Structure and Unions?
25. What the advantages of using Unions?
26. What are the advantages of using pointers in a program?
27. What is the difference between Strings and Arrays?
28. In a header file whether functions are declared or defined?
29. What is a far pointer? where we use it?
30. How will you declare an array of three function pointers
where each function receives two ints and returns a float?
31. what is a NULL Pointer? Whether it is same as an
uninitialized pointer?
32. What is a NULL Macro? What is the difference between a NULL
Pointer and a NULL Macro?
33. What does the error 'Null Pointer Assignment' mean and what
causes this error?
34. What is near, far and huge pointers? How many bytes are
occupied by them?
35. How would you obtain segment and offset addresses from a far
address of a memory location?
36. Are the expressions arr and &arr same for an array of
integers?
37. Does mentioning the array name gives the base address in all
the contexts?
38. Explain one method to process an entire string as one unit?
39. What is the similarity between a Structure, Union and
enumeration?
40. Can a Structure contain a Pointer to itself?
41. How can we check whether the contents of two structure
variables are same or not?
42. How are Structure passing and returning implemented by the
complier?
43. How can we read/write Structures from/to data files?
44. What is the difference between an enumeration and a set of
pre-processor # defines?
45. what do the 'c' and 'v' in argc and argv stand for?
46. Are the variables argc and argv are local to main?
47. What is the maximum combined length of command line arguments
including the space between adjacent arguments?
48. If we want that any wildcard characters in the command line
arguments should be appropriately expanded, are we required to make
any special provision? If yes, which?
49. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to the
function?
50. What are bit fields? What is the use of bit fields in a
Structure declaration?
51. To which numbering system can the binary number
1101100100111100 be easily converted to?
52. Which bit wise operator is suitable for checking whether a
particular bit is on or off?
53. Which bit wise operator is suitable for turning off a
particular bit in a number?
54. Which bit wise operator is suitable for putting on a
particular bit in a number?
55. Which bit wise operator is suitable for checking whether a
particular bit is on or off?
56. which one is equivalent to multiplying by 2:Left shifting a
number by 1 or Left shifting an unsigned int or char by 1?
57. Write a program to compare two strings without using the
strcmp() function.
58. Write a program to concatenate two strings.
59. Write a program to interchange 2 variables without using the
third one.
60. Write programs for String Reversal & Palindrome check
61. Write a program to find the Factorial of a number
62. Write a program to generate the Fibinocci Series
63. Write a program which employs Recursion
64. Write a program which uses Command Line Arguments
65. Write a program which uses functions like strcmp(), strcpy()?
etc
66. What are the advantages of using typedef in a program?
67. How would you dynamically allocate a one-dimensional and two-
dimensional array of integers?
68. How can you increase the size of a dynamically allocated
array?
69. How can you increase the size of a statically allocated
array?
70. When reallocating memory if any other pointers point into the
same piece of memory do you have to readjust these other pointers or
do they get readjusted automatically?
71. Which function should be used to free the memory allocated by
calloc()?
72. How much maximum can you allocate in a single call to malloc
()?
73. Can you dynamically allocate arrays in expanded memory?
74. What is object file? How can you access object file?
75. Which header file should you include if you are to develop a
function which can accept variable number of arguments?
76. Can you write a function similar to printf()?
77. How can a called function determine the number of arguments
that have been passed to it?
78. Can there be at least some solution to determine the number
of arguments passed to a variable argument list function?
79. How do you declare the following:
o An array of three pointers to chars
o An array of three char pointers
o A pointer to array of three chars
o A pointer to function which receives an int pointer and
returns a float pointer
o A pointer to a function which receives nothing and returns
nothing
80. What do the functions atoi(), itoa() and gcvt() do?
81. Does there exist any other function which can be used to
convert an integer or a float to a string?
82. How would you use qsort() function to sort an array of
structures?
83. How would you use qsort() function to sort the name stored in
an array of pointers to string?
84. How would you use bsearch() function to search a name stored
in array of pointers to string?
85. How would you use the functions sin(), pow(), sqrt()?
86. How would you use the functions memcpy(), memset(), memmove
()?
87. How would you use the functions fseek(), freed(), fwrite()
and ftell()?
88. How would you obtain the current time and difference between
two times?
89. How would you use the functions randomize() and random()?
90. How would you implement a substr() function that extracts a
sub string from a given string?
91. What is the difference between the functions rand(), random
(), srand() and randomize()?
92. What is the difference between the functions memmove() and
memcpy()?
93. How do you print a string on the printer?
94. Can you use the function fprintf() to display the output on
the screen?



C Project : Quiz Maker

/****************************************************************************
* Quiz Maker : This C Project contain code for making Quiz, it will help *
* u in making quiz as per ur requirement. Here Sample Quiz of*
* Hex_to_Bin conversion is taken u can change as per ur *
* requirement. *
* ------------------------------------------------------------------------ *
* Author : Vivek Patel *
* Ahmedabad.INDIA *
* email : vivek_patel9@rediffmail.com *
* Website: http://www.vivekpatel.cjb.net *
* ------------------------------------------------------------------------ *
****************************************************************************/


//Quiz Maker

//Tested by hex2bin quiz making
//Change Quiz as per ur question and answers...
//Feel Free to ask ur queries : vivek_patel9@rediffmail.com

//You are requested not to change code except the comment indicating
//u to change it...otherwise it will not suit ur requirement..


#include
#include
//#include

//int gdriver=DETECT, gmode;

void scorecard(int);//pass quizno.
void quizbox(int,int,int,int,int);
//void statusmsg(int);

void main(){
int i;
char ch;
for(i=0;i<15;i++){
if(ch==27)
exit(1);
clrscr();
textcolor(LIGHTGREEN);
quizbox(28,1,50,3,2);
gotoxy(30,2);
textcolor(YELLOW);
cprintf("***** QUIZ %d *****",i+1); //Quiz No. currently executed
gotoxy(25,15);
cprintf("Programmed by : Vivek Patel");
gotoxy(25,18);
cprintf("Email: vivek_patel9@rediffmail.com");
gotoxy(25,19);
cprintf("Website: www.vivekpatel.cjb.net");
textcolor(DARKGRAY);
quizbox(23,5,57,11,2);
textcolor(LIGHTMAGENTA);
switch(i){
//Here formating code is redundant u can make a function and call it
//each time...
case 0 : gotoxy(29,6);
//Question 1
//Enter ur Question instead of "Find Hexadecimal to Binary?"
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","9.1A");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i); //For Testing Current Score
//This Comments will be followed to Rest of Questions...
//You can also increase or decrease questions...in quiz
break;
case 1 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","BA4");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 2 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","C8");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 3 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","15");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 4 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","D89F");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 5 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","64AC");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 6 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","9A6");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 7 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","CDAC");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 8 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","DEAF");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 9 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","CAFE");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 10 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","FADE");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 11: gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","FEE");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 12 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","5C");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 13 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","FACE");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
case 14 : gotoxy(29,6);
cprintf("Find Hexadecimal to Binary?");
gotoxy(29,7);
cprintf("For below Given Number!");
gotoxy(35,8);
cprintf(" %-8s","AEC");
gotoxy(30,9);
cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
scorecard(i);
break;
}
textcolor(LIGHTGRAY);
gotoxy(55,2);
cprintf("Escape to Return");
gotoxy(55,3);
cprintf("Any key to continue...");
flushall();
ch=getch();
}
}


void scorecard(int quizno){
static int right=0,wrong=0,totattempt=0,currentscore=0;
char userans[25];

//Enter answers of quiz respectively for all questions
//In the below given...array
//ans1 ans2 ans3 ans4 ans5 and so on....
char quizans[15][25]={"1001.00011010","101110100100","11001000","10101","1101100010011111","110010010101100","100110100110","1100110110101100","1101111010101111","1100101011111110","1111101011011110","111111101110","1011100","1111101011001110","101011101100"};
gotoxy(34,10);
scanf("%s",&userans);
strupr(userans);
textcolor(DARKGRAY);
quizbox(22,12,58,15,2);
textcolor(LIGHTMAGENTA);
if(strcmp(quizans[quizno],userans)==0){
right++;
textcolor(LIGHTGREEN + BLINK);
gotoxy(35,13);
cprintf("RIGHT!!!");
}
else{
wrong++;
textcolor(LIGHTRED + BLINK);
gotoxy(35,13);
cprintf("WRONG");
textcolor(LIGHTGREEN);
gotoxy(24,14);
cprintf("Correct Answer is %s",quizans[quizno]);
}
totattempt++;
currentscore=(int)((right * 100)/totattempt);

textcolor(LIGHTGRAY);
quizbox(22,16,58,18,2);//for score board
quizbox(22,19,58,25,2);//for it's details

textcolor(LIGHTCYAN);
gotoxy(35,17);
cprintf("SCORE BOARD");
textcolor(WHITE);
gotoxy(25,20);
cprintf("Total Right : %d",right);
gotoxy(25,21);
cprintf("Total Wrong : %d",wrong);
gotoxy(25,22);
cprintf("Total Attempt : %d out of 15",totattempt);
gotoxy(23,23);
printf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
gotoxy(25,24);
textcolor(YELLOW);
cprintf("Current Score : %d",currentscore);
/* if(quizno==14){
getch();
statusmsg(currentscore);
exit(1);
}
*/
}





void quizbox(int x1, int y1, int x2, int y2,int linestyle)
{
int col,row;
if(linestyle==1){
for (col = x1; col < x2; col++)
{
gotoxy(col, y1);
cprintf("%c", 196);
gotoxy(col, y2);
cprintf("%c", 196);
}

for (row = y1; row < y2; row++)
{
gotoxy(x1, row);
cprintf("%c", 179);
gotoxy(x2, row);
cprintf("%c", 179);
}

gotoxy(x1, y1);
cprintf("%c", 218);
gotoxy(x1, y2);
cprintf("%c", 192);
gotoxy(x2, y1);
cprintf("%c", 191);
gotoxy(x2, y2);
cprintf("%c", 217);
}
else{
for (col = x1; col < x2; col++)
{
gotoxy(col, y1);
cprintf("%c", 205);
gotoxy(col, y2);
cprintf("%c", 205);
}

for (row = y1; row < y2; row++)
{
gotoxy(x1, row);
cprintf("%c", 186);
gotoxy(x2, row);
cprintf("%c", 186);
}

gotoxy(x1, y1);
cprintf("%c", 201);
gotoxy(x1, y2);
cprintf("%c", 200);
gotoxy(x2, y1);
cprintf("%c", 187);
gotoxy(x2, y2);
cprintf("%c", 188);
}
}



//Lastly Giving Greet According to Quiz Status
// Use the section only if u have knowledge of Graphics
/*
void statusmsg(int score){
initgraph(&gdriver, &gmode,"c:\\tc\\bgi");
setcolor(LIGHTMAGENTA);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
outtextxy(5,415,"Programmer : VIVEK PATEL");
outtextxy(5,435,"E-Correspondence : vivek_patel9@rediffmail.com");
outtextxy(5,455,"WebSite : www.vivekpatel.cjb.net");

setcolor(YELLOW);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,8);
if(score==100)
outtextxy(50,50,"KEEP IT UP!");
else if(score>=85)
outtextxy(50,50,"Well Done!");
else if(score>=75)
outtextxy(100,50,"Good");
else if(score>=70)
outtextxy(20,50,"Practise Require!");
else if(score>=60)
outtextxy(20,50,"Revision Needed!");
else if(score>=50)
outtextxy(50,50,"Work Hard!");
else
outtextxy(50,50,"Read Tutorial!");

getch();
closegraph();
}
*/



Write a C Program to display Progressbar (Graphics)

/****************************************************************************
* ProgressBar : This programm contains code for progressbar it work *
* same as progressbar displayed in window's environment. *
* (Progressbar for Graphics program) *
* ------------------------------------------------------------------------ *
* Author : Vivek Patel *
* Ahmedabad.INDIA *
* email : vivek_patel9@rediffmail.com *
* WWW : http://www.geocities.com/vivek_patel9/index.html *
* ------------------------------------------------------------------------ *
****************************************************************************/



#include
#include
#include
#include

#define CNT_ROW 5 //Counter in ProgressBar's --> Col position
#define CNT_COL 40 //Counter in ProgressBar's --> Row position

#define PROGRESS_X1 200//ProgressBar's --> Starting position
#define PROGRESS_X2 460//ProgressBar's --> Ending position

#define PROGRESS_Y1 55 //ProgressBar's --> Starting Height
#define PROGRESS_Y2 85 //ProgressBar's --> Ending Height

#define delayTime 50 //Speed of ProgressBar

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int i,j,cnt=0,clrflag=0;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

/*-------Introduction Line----------*/
setcolor(LIGHTGREEN);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
outtextxy(5,100,"Graphical ProgressBar");
setcolor(LIGHTCYAN);
settextstyle(SMALL_FONT,HORIZ_DIR,6);
outtextxy(5,180,"Programmed By : Vivek Patel");
outtextxy(5,200,"Email : vivek_patel9@rediffmail.com");
outtextxy(5,220,"Website : www.vivekpatel.cjb.net");
/*-------Introduction Line----------*/

setcolor(CYAN);
j=PROGRESS_X1;
cnt=5;
for(i=j;i delay(delayTime);
gotoxy(CNT_COL,CNT_ROW);
printf("%d",cnt);
rectangle(j,PROGRESS_Y1,i,PROGRESS_Y2);
if(i==(j+10)){
j=j+13;
i=j;
if(clrflag==1){
clrflag=0;
setcolor(CYAN);
}
else{
clrflag=1;
setcolor(BLUE);
}
cnt=cnt+5;
}
}

setcolor(WHITE);
outtextxy(5,260,"Press Any Key to Return...");




/* clean up */
getch();
// closegraph();
return 0;
}



Write a C Program to display Progressbar

/****************************************************************************
* ProgressBar : This programm contains code for progressbar it work *
* same as progressbar displayed in window's environment. *
* (Progressbar for Non-Graphics program) *
* ------------------------------------------------------------------------ *
* Author : Vivek Patel *
* Ahmedabad.INDIA *
* email : vivek_patel9@rediffmail.com *
* WWW : www.vivekpatel.cjb.net *
****************************************************************************/



#include
#include
#include

/*
start_x : x-axis starting (progressbar starting[x-cordinate])
end_x : x-axis ending (progressbar ending[x-cordinate])
y : Row no. where progressbar should be placed
symbol : Symbol to be displayed
style : 0 for smooth progressbar
1 for rough progressbar
dlytime : delay time (in milliseconds)

fillclr : fill color for progressbar
fillbkclr : fill backcolor for progressbar

color may be from following option...
Constant ³Value
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍ
BLACK ³ 0
BLUE ³ 1
GREEN ³ 2
CYAN ³ 3
RED ³ 4
MAGENTA ³ 5
BROWN ³ 6
LIGHTGRAY ³ 7
DARKGRAY ³ 8
LIGHTBLUE ³ 9
LIGHTGREEN ³ 10
LIGHTCYAN ³ 11
LIGHTRED ³ 12
LIGHTMAGENTA ³ 13
YELLOW ³ 14
WHITE ³ 15

*/
void progressbar(int start_x,int end_x,int y,char symbol,int style,int dlytime,int fillclr,int fillbkclr)
{
int i,len,temp,dly;
len=end_x-start_x;
dly=dlytime/len;

_setcursortype(_NOCURSOR);

textbackground(fillbkclr);
temp=start_x;
for (i=1;i<=len+1;++i,++start_x)
{
gotoxy(start_x,y);
cprintf("%c",symbol);
}
start_x=temp;
gotoxy(start_x,y);


textbackground(fillclr);
temp=start_x;
for (i=1;i<=len+1;++i,++start_x)
{
if(style==1){
if(i%2!=0){
gotoxy(start_x,y);
delay(dly);
cprintf("%c",symbol);
}
}
else{
gotoxy(start_x,y);
delay(dly);
cprintf("%c",symbol);
}
}

gotoxy(temp,y+1);
_setcursortype(_NORMALCURSOR);

}

void main(){
clrscr();
/*examples*/
progressbar(20,50,12,' ',0,2000,BLUE,LIGHTGRAY);
progressbar(10,70,14,' ',0,500,RED,YELLOW);
progressbar(30,40,16,' ',0,15000,MAGENTA,LIGHTGREEN);
getch();
}



Write a C Program to Run .Exe File

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(int argc,char *argv[])
{
//int i;

spawnv(P_WAIT,"ims.EXE", argv);

perror("exec error");
exit(1);
}



Write a C Program demonstrating xstrstr() function

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
char * xstrstr(char *,char *);
char *string;
char *ptr,c[15];
clrscr();
printf("Enter a string : ");
gets(string);
printf("Enter search string : ");
gets(c);
ptr = xstrstr(string, c);
printf("\nOutput of function is : %s\n",ptr);
getch();
}

char * xstrstr(char *str,char *ch){
int i,j,len,k;
char *temp;
for(len=0;ch[len];len++); // for lenngth
for(i=0;str[i];i++){
for(j=0;j temp[j]=str[i+j];
temp[j]='\0';
if(strcmp(temp,ch)==0){
for(k=j;str[i+k];k++)
temp[k]=str[i+k];
temp[k]='\0';
return(temp);
}
}
return(0);
}



Write a C Program demonstrating xstrchr() function

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
char * xstrchr(char *,char);
char string[15];
char *ptr,c;
clrscr();
printf("Enter a string : ");
scanf("%[^\n]s",string);
printf("Enter search character : ");
flushall();
scanf("%c",&c);
ptr = xstrchr(string, c);
printf("\nOutput of function is : %s\n",ptr);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
getch();
}

char * xstrchr(char *str,char ch){
int i;
for(i=0;str[i];i++){
if(str[i]==ch)
return ((str+i)+1);
}
return(0);
}



Write a C Program to Find Total No. of Vowels in a given string

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int chasc,i,cnt=0;
char ch,str[40]="";
clrscr();
printf("*****Vowels Demo*****\n\n");
printf("enter string : ");
scanf("%[^\n]s",str);
for(i=0;str[i]!='\0';i++)
{
chasc = str[i];
switch(chasc){
case 'a' :
case 'A' :
case 'e' :
case 'E' :
case 'i' :
case 'I' :
case 'o' :
case 'O' :
case 'u' :
case 'U' :
cnt++;
}
}

printf("\nTotal number of vowels is %d",cnt);
getch();
}



Write a C Program to display triangle

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/
#include
#include
void main(){
int i,j,k,n;
clrscr();
printf("Enter num : ");
scanf("%d",&n);
for(i=n;i>0;i--){
for(k=i;k>0;k--)
printf(" ");
for(j=0;j<(n-(i-1));j++)
printf("%3c",'*');
printf("\n");
}
getch();
}



Write a prog to swap even positioned chars with odd positioned chars in a given string.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
void main(){
char str[20],tmp;
int i,j;
clrscr();
printf("\nEnter a string : ");
scanf("%s",str);
printf("\n\nOriginal String : %s",str);
for(i=0;i tmp = str[i];
str[i] = str[i+1];
str[i+1] = tmp;
}
printf("\nAfter Swap String : %s",str);
getch();
}



Write a C Program for extracting sub-string from string

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int m,n,i,len;
char str[40]="",substr[40]="";
clrscr();
printf("*****SubString Demo*****\n\n");
printf("Enter string : ");
scanf("%[^\n]s",str);
for(m=0;str[m]!='\0';m++);

len = m;

printf("\nString Extracting Details\n");
strt:
printf("enter starting position : ");
scanf("%d",&m);
printf("enter ending position : ");
scanf("%d",&n);

if(m<=0 || m>len || nlen){
printf("\n\nInvalid Input\n\n");
goto strt;
}
else{
for(i=0;m<=n;m++,i++)
substr[i]=str[m-1];
substr[i]='\0';
printf("\nSub String is %s",substr);
}

getch();
}



Write a C Program for String Output

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
void main(){
int len;
char s[]="VIVEK PATEL";
clrscr();
len = strlen(s);
while(len>0){
printf("\n%-15.*s",len,s);
len--;
}
getch();
}



Write a C Program for String Copy

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
void main(){
char str1[20],str2[20],ch;
int i;
clrscr();
printf("*****Strings Copy Function*****\n\n");
printf("Enter string1: ");
scanf("%s",str1);
printf("\n\nUsing Inbuilt Function");
strcpy(str2,str1);
printf("\nString1 : %s\nString2 : %s\n",str1,str2);

strcpy(str2,""); //empty to copy again
printf("\n\nWithout Using Inbuilt Function");
for(i=0;str1[i]!='\0';i++)
str2[i] = str1[i];
str2[i]='\0';
printf("\nString1 : %s\nString2 : %s\n",str1,str2);

getch();
}



Write a C Program to Concat string

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/


#include
#include
#include
void main(){
char str1[20],str2[20],str3[40]="";
int len,i,j;
clrscr();
printf("*****Strings Concatination Function*****\n\n");
printf("Enter string1: ");
scanf("%s",str1);
printf("Enter string2: ");
scanf("%s",str2);

for(i=0,j=0;str1[i]!='\0';i++,j++)
str3[j] = str1[i];

for(i=0;str2[i]!='\0';i++,j++)
str3[j] = str2[i];

str3[j] = '\0';
len = j;

printf("\n\nAfter Concatination : %s",str3);
printf("\n\nLength of concated string is %d",len);
getch();
}



C Project : Write a C Program for Telepone directory

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

struct person{
char name[20];
long telno;
};

void appendData(){
FILE *fp;
struct person obj;
clrscr();
fp=fopen("data.txt","a");
printf("*****Add Record****\n");
printf("Enter Name : ");
scanf("%s",obj.name);
printf("Enter Telephone No. : ");
scanf("%ld",&obj.telno);
fprintf(fp,"%20s %7ld",obj.name,obj.telno);
fclose(fp);
}

void showAllData(){
FILE *fp;
struct person obj;
clrscr();
fp=fopen("data.txt","r");
printf("*****Display All Records*****\n");
printf("\n\n\t\tName\t\t\tTelephone No.");
printf("\n\t\t=====\t\t\t===============\n\n");
while(!feof(fp))
{
fscanf(fp,"%20s %7ld",obj.name,&obj.telno);
printf("%20s %30ld\n",obj.name,obj.telno);
}
fclose(fp);
getch();
}

void findData(){
FILE *fp;
struct person obj;
char name[20];
int totrec=0;
clrscr();
fp=fopen("data.txt","r");
printf("*****Display Specific Records*****\n");
printf("\nEnter Name : ");
scanf("%s",&name);
while(!feof(fp))
{
fscanf(fp,"%20s %7ld",obj.name,&obj.telno);
if(strcmpi(obj.name,name)==0){
printf("\n\nName : %s",obj.name);
printf("\nTelephone No : %ld",obj.telno);
totrec++;
}
}
if(totrec==0)
printf("\n\n\nNo Data Found");
else
printf("\n\n===Total %d Record found===",totrec);
fclose(fp);
getch();
}



void main(){
char choice;
while(1){
clrscr();
printf("*****TELEPHONE DIRECTORY*****\n\n");
printf("1) Append Record\n");
printf("2) Find Record\n");
printf("3) Read all record\n");
printf("4) exit\n");
printf("Enter your choice : ");
fflush(stdin);
choice = getche();
switch(choice){
case '1' : //call append record
appendData();
break;
case '2' : //call find record
findData();
break;
case '3' : //Read all record
showAllData();
break;
case '4' :
case 27 : exit(1);
}
}
}



Write a C Program to Sort given data

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int *arr,i,j,tmp,n;
printf("Enter how many data you want to sort : ");
scanf("%d",&n);
for(i=0;i scanf("%d",arr+i);

for(i=0;i {
for(j=i+1;j if( *(arr+i) > *(arr+j)){
tmp = *(arr+i);
*(arr+i) = *(arr+j);
*(arr+j) = tmp;
}
}
}

printf("\n\nAfter Sort\n");
for(i=0;i printf("%d\n",*(arr+i));

getch();
}



Write a C Program to demonstrating graphics - screen saver

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
#include

void main(){
int gdriver=DETECT,gmode;
int left=200,top=200,right=700,bottom=700,color=15,pat=8;
initgraph(&gdriver,&gmode,"");
cleardevice();
while(!kbhit()){
setfillstyle(random(pat),random(color));
bar(random(left),random(top),random(right),random(bottom));
delay(250);
}
closegraph();
}



Write a C Program to demonstrating graphics

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
#include

void main(){
int gdriver=DETECT,gmode,col=400,row=600,font=4,direction=2,size=8,color=15;
initgraph(&gdriver,&gmode,"");
cleardevice();
while(!kbhit()){
settextstyle(random(font),random(direction),random(size));
setcolor(random(color));
outtextxy(random(col),random(row),"Vivek Patel");
delay(250);
}
closegraph();
}



Write a C Program demonstrating Multi dimensional array

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int salitm[4][3],i,j,itmtot[3]={0},salpertot[4]={0};
clrscr();
printf("*****Sales Item Demo*****\n\n");
printf("Enter details for 4 salesman and 3 items\n");
//logic
for(i=0;i<4;i++){
for(j=0;j<3;j++){
scanf("%d",&salitm[i][j]);
salpertot[i] = salpertot[i] + salitm[i][j];
itmtot[j] = itmtot[j] + salitm[i][j];
}
}

//display
printf("\n\n\tItem1\tItem2\tItem3\n");
for(i=0;i<4;i++){
printf("%s%-4d","S",i+1);
for(j=0;j<3;j++){
printf("%*d",7+j,salitm[i][j]);
}
printf("\n");
}

printf("\nItem Wise total\n");
for(j=0;j<3;j++)
printf("%s%-3d=%5d\t","Item",j+1,itmtot[j]);

printf("\n\nSalesman Wise total\n");
for(j=0;j<4;j++)
printf("%s%-3d=%5d\t","S",j+1,salpertot[j]);

getch();
}



Write a prog. that will rotate string, typed in to it.

/*Write a prog. that will rotate string, typed in to it.
eg: "space"
paces acesp cespa espac
*/


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
void main(){
char name[20];
int i,j,k;
clrscr();
printf("\nEnter a string : ");
scanf("%s",name);
for(i=0;i printf("\n");
for(j=i+1;j printf("%c",name[j]);
for(k=0;k<=i;k++)
printf("%c",name[k]);
}
getch();
}



Wrtie a C Program to Generate Random Number

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
int i,cnt=0,rnd;
clrscr();
while(1){
rnd=random(100);
if(rnd>50 && rnd<100){
printf("\nRandom No [%d] : %d ",cnt+1,rnd);
cnt++;
}
if(cnt==10)
break;
}
getch();
}



Write a C Program to generate Pyramid

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int i,j,k,m,num,c,tmp;
clrscr();
printf("*****PYRAMID*****\n\n");
printf("Enter num of lines : ");
scanf("%d",&num);
for(i=1;i<=num;i++){
c=i;
for(k=1;k<=(num-i);k++)
putchar(' ');

for(j=i;j>=1;j--){
if(c>9){
printf("%d",0);
tmp=c;
}
else{
printf("%d",c++);
tmp=c;
}
}
tmp--;

for(m=tmp;m>i;)
printf("%d",--m);

printf("\n");
}
getch();
}



Write a program to find first N prime numbers.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int n,i,c=0,j,flag;
clrscr();
printf("*****Finding First N PRIME NUMBERS*****\n\n");
printf("Enter number : ");
scanf("%d",&n);

for(i=2;c for(j=2;j if(i%j == 0)
goto out;
}
printf("\n%3d is a PRIME NUMBER",i);
c++;
out:
}

getch();
}



Program to Find Whether Number entered is PRIME or NOT.

//Program to Find Whether Number entered is PRIME or NOT.


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int num,i;
clrscr();
printf("*****PRIME NUMBER*****\n\n");
printf("Enter the number to find it is prime or not : ");
scanf("%d",&num);
for(i=2;i if(num%i==0){
printf("\n\n%d is Not a Prime Number\n",num);
printf("It is divisible by %d, ...",i);
goto out;
}
}
printf("\n\n%d is a PRIME number",num);
out:
getch();
}



Write a C Program for pelindrome string

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int pelin(char[]);
int flag;
char str[30];
clrscr();
printf("*****PELINDROME STRING*****\n\n");
printf("Enter string : ");
scanf("%s",str);
if(pelin(str))
printf("\nSTRING IS PELINDROME");
else
printf("\nSTRING IS NOT PELINDROME");

getch();
}


int pelin(char str[]){
int flag=0,i,j;
char rev[30];
for(i=0;str[i]!='\0';i++)
rev[i] = str[i];
//checking whether pelindrome
i--;
for(j=0;i>=0;j++,i--){
if(rev[j]!=str[i]){
flag=0;
return(flag);
}
}
flag=1;
return (flag);
}



Write a program to print the following outputs using for loops.

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int i,j,k,num;
clrscr();
printf("*****DIGIT TRIANGLE*****\n");
printf("Enter number : ");
scanf("%d",&num);
for(i=1;i<=num;i++){
for(k=num;k>=i;k--)
printf("%c",' ');
for(j=1;j<=i;j++)
printf("%3d",i);
printf("\n");
}

getch();
}



Write a program to print the following outputs using for loops.

/*
Write a program to print the following outputs using for loops.

B) * * * * *
* * * *
* * *
* *
*
*/


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int i,j,k;
clrscr();
printf("*****Reverse Triangle*****\n");
for(i=1;i<=5;i++){
for(k=1;k<=i;k++)
printf("%3c",' ');
for(j=5;j>=i;j--){
printf("%3c",'*');
}
printf("\n");
}
getch();
}



Write a program to print the following outputs using for loops.

/*
Write a program to print the following outputs using for loops.

A) 1
2 2
3 3 3
4 4 4 4...
*/


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int i,j,num;
clrscr();
printf("*****RightAngle Triangular Format*****\n");
printf("Enter number : ");
scanf("%d",&num);
for(i=1;i<=num;i++){
for(j=1;j<=i;j++){
printf("%5d",i);
}
printf("\n");
}
getch();
}



Write a prog to produce following output

/*Write a prog to produce output like
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A*/


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
char i,a,b,c,d;
int p;
clrscr();
printf("\n*****output*******\n\n");
for(i='G';i>='A';i--){

for(a='A';a<=i;a++)
{
if(a!='G')
printf("%c",a);
}

for(b='G';b>i;b--)
printf(" ");

for(c='F';c>i;c--)
printf(" ");

for(p=i;p>='A';p--)
printf("%c",p);

printf("\n");
}
getch();
}



Write a C Program for string sorting

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
int i,n;
char name[15][20];
void namesort(char name[15][20], int);
clrscr();
printf("How many names u want to enter : ");
scanf("%d",&n);
printf("\n\n****Enter Input Data****\n");
for(i=0;i flushall();
printf("Enter a name : ");
gets(name[i]);
}
namesort(name,n);
printf("\n\n\n******After Sorting******\n");
for(i=0;i printf("%s\n",name[i]);
getch();
}

void namesort(char name[15][20],int n){
int i,j;
char *temp;
for(i=0;i for(j=0;j if(strcmp(name[j],name[j+1])>0){
strcpy(temp,name[j]);
strcpy(name[j],name[j+1]);
strcpy(name[j+1],temp);
}
}
}
}



Program to Generate Multiplication Table

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int i,j,num;
clrscr();
printf("\n*****MULTIPLICATION TABLE*****\n\n");
printf("Enter number upto which u want to generate : ");
scanf("%d",&num);
for(i=1;i<=num;i++){
for(j=1;j<=num;j++){
printf("%5fsd",(i*j));
}
printf("\n");
}
getch();
}



Write a C Program, demonstrating Merge File Scenario

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include


void main(int argc,char *argv[]){
FILE *fmrg,*fd1,*fd2;
int data1[]={1,3,9,15,18,20,30};
int data2[]={2,3,5,8,9,23,28};
int i,data,tmp1,tmp2;

clrscr();
fd1 = fopen("data1.txt","w");
for(i=0;i<7;i++)
putw(data1[i],fd1);
fclose(fd1);

fd2 = fopen("data2.txt","w");
for(i=0;i<7;i++)
putw(data2[i],fd2);
fclose(fd2);

fmrg = fopen(argv[1],"w");
fd1 = fopen("data1.txt","r");
fd2 = fopen("data2.txt","r");
//merge logic
while(!feof(fd1)){
data = getw(fd1);
putw(data,fmrg);
}
while(!feof(fd2)){
data = getw(fd2);
putw(data,fmrg);
}
fclose(fd1);
fclose(fd2);
fclose(fmrg);

printf("\n\n***After Merging Files***\n\n");
fmrg = fopen(argv[1],"r");
while(!feof(fmrg))
{
data = getw(fmrg);
printf("%5d",data);
}
fclose(fmrg);

/*
//sort logic
fd1 = fopen(argv[1],"r");
fd2 = fopen(argv[1],"r");
while(!feof(fd1)){
fseek(fd1,2L,SEEK_CUR);
tmp1 = getw(fd1);
while(!feof(fd2)){
fseek(fd2,2L,SEEK_CUR);
tmp2 = getw(fd2);
if(tmp1 > tmp2)
*/
getch();
}



Write a C Program displaying Logical Square

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int i,j,k,m,num,c;
clrscr();
printf("*****Logical Square*****\n");
printf("Enter number of lines u want : ");
scanf("%d",&num);
printf("\n\n");
//for top part
for(i=1;i < num;i++)
{
c=num;
for(j=1; j <=(num-i)+2;j++)
putchar(' ');
for(k=1;k<=i;k++)
printf("%d",c--);
c++;
for(m=c;m printf("%d",++c);
}
printf("\n");
}

//for bottom part
for(i=1;i<=num;i++){
c=num;
for(j=num;j>=(num-i);j--)
putchar(' ');
for(k=c;k>i;k--)
printf("%d",k);
for(m=k;m<=c;m++)
printf("%d",m);
printf("\n");
}

getch();
}



Write a C Program demonstrating Link List

/*LinkList*/


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

struct node
{
int data;
struct node *next;
};

void main(){
node *create(),*head;
void display(node *);
int count(node *);
void sort(node *);
int key;
clrscr();
while(1){
if(key==27)
break;
else{
head=create();
display(head);
sort(head);
}
printf("\nPress Escape to return...");
key=getch();
}
}

node *create(void){
node *start=NULL,*newl=NULL,*endl=newl;
int take;
while(1){
printf("\nEnter -1 at end\n");
printf("Enter data : ");
scanf("%d",&take);
if(take==-1)
break;
else{
newl = (node *)malloc(sizeof(node));
newl->data = take;
if(start==NULL)
start=newl;
else
endl->next = newl;
endl=newl;
endl->next=NULL;
}
}
return(start);
}


void display(node *start){
printf("\ndisplay\n");
while(start!=NULL){
printf("%d",start->data);
if(start->next!=NULL)
printf("==>");
start=start->next;
}
}

int count(node *start){
int cnt=0;
while(start!=NULL){
cnt++;
start = start->next;
}
return(cnt);
}


void sort(node *start){
node *temp1=start,*temp2=start;
int tmpdata;
while(temp1!=NULL){
while(temp2->next!=NULL){
if(temp1->data > temp2->next->data){
tmpdata = temp2->next->data;
temp2->next->data = temp1->data;
temp1->data = tmpdata;
}
temp2=temp2->next;
}
temp1=temp1->next;
}

}



Find out the G.C.F. and L.C.F. of given two numbers.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

int num1,num2,choice,temp1,temp2;

void lcm(){
int i,lcm=1;
num1 = temp1;
num2 = temp2;
printf("\n\nL.C.M OF NUMBER\n");
while(num1>1 || num2>1){
for(i=2;i<100;i++){
if(num1%i==0 || num2%i==0){
printf("\n%4d | %4d , %4d",i,num1,num2);
if(num1%i==0){
num1 = num1/i;
}
if(num2%i==0){
num2 = num2/i;
}
lcm = lcm * i;
}
}
}
printf("\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
printf("\n%4d | %4d , %4d",lcm,1,1);
printf("\n\nLCM IS %d",lcm);
}

void gcf(){
int i,gcfnum1=1,gcfnum2=1,cntnum1[100]={0},cntnum2[100]={0},gcf=1;
num1 = temp1;
num2 = temp2;
printf("G.C.F. OF NUMBER\n");
//For num1
while(num1>1){
for(i=2;i<100;i++){
if(num1%i==0){
printf("\n%4d | %4d ",i,num1);
num1 = num1/i;
gcfnum1 = gcfnum1 * i;
cntnum1[i]++;
}
}
}
printf("\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
printf("\n%4d | %4d ",gcfnum1,1);
printf("\nGCF IS %d",gcfnum1);
printf("\n%-4d = ",temp1);
for(i=2;i<100;i++){
if(cntnum1[i]>0)
printf(" (%3d^%-3d) ",i,cntnum1[i]);
}


//For num2
printf("\n\n");
while(num2>1){
for(i=2;i<100;i++){
if(num2%i==0){
printf("\n%4d | %4d ",i,num2);
num2 = num2/i;
gcfnum2 = gcfnum2 * i;
cntnum2[i]++;
}
}
}
printf("\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
printf("\n%4d | %4d ",gcfnum2,1);
printf("\n\nGCF IS %3d",gcfnum2);
printf("\n%-4d = ",temp2);
for(i=2;i<100;i++){
if(cntnum2[i]>0)
printf(" (%3d^%-3d) ",i,cntnum2[i]);
}

//GCF logic
for(i=2;i<100;i++){
if(cntnum1[i]==0 || cntnum2[i]==0)
continue;
else if(cntnum1[i] < cntnum2[i])
gcf = gcf * pow(i,cntnum1[i]);
else if(cntnum2[i] gcf = gcf * pow(i,cntnum2[i]);
else if(cntnum1[i]>0)
gcf = gcf * pow(i,cntnum1[i]);
else if(cntnum2[i]>0)
gcf = gcf * pow(i,cntnum2[i]);
}

printf("\n\nGCF of %d and %d is %d",temp1,temp2,gcf);
}

void main(){
void lcm(void);
void gcf(void);
clrscr();
printf("*****LCM And GCF of Given Numbers*****");
up:
printf("\n\nEnter num1 : ");
scanf("%d",&num1);
printf("Enter num2 : ");
scanf("%d",&num2);
temp1 = num1;
temp2 = num2;
while(1){
clrscr();
printf("\n\nChoose your Choice\n");
printf("1) L.C.M\n");
printf("2) G.C.F\n");
printf("3) Scan New Numbers\n");
printf("4) Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice){
case 1 : clrscr();
lcm();
break;
case 2 : clrscr();
gcf();
break;
case 3 : goto up;
case 4 :
exit(1);
default: printf("\n\nINVALID CHOICE\n");
}
getch();
}
}



Program to Generate Modified Floyd's Triangle.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int i,j,num,c=1;
clrscr();
printf("*****FLOYD'S TRIANGLE*****\n\n");
printf("Enter number upto which u want to generate : ");
scanf("%d",&num);
for(i=c;i<=num;i++){
for(j=1;j<=i;j++,c++){
printf("%5d",c);
if(c==num)
goto out;
}
printf("\n");
}
out:
getch();
}



Program to Generate Floyd's Triangle.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int i,j,num,c=1;
clrscr();
printf("*****Modified FLOYD'S TRIANGLE*****\n\n");
printf("Enter number upto which u want to generate : ");
scanf("%d",&num);
for(i=1;i<=91;i++){
for(j=1;j<=i;j++,c++){
printf("%5d",((i+j+1)%2));
if(c==num)
goto out;
}
printf("\n");
}
out:
getch();
}



Write a C Programm to find whether input character is digit, alphabet, alphanumeric

//Enter the character one by one last is zero and display the
//type of that character. if it is alphabetic then convert into the
//uppercase.


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
char ch;
clrscr();
while(1){
printf("\nEnter ZERO to Terminate \n");
printf("Enter any character : ");
scanf("%c",&ch);
if(ch=='0')
break;
else if(isspace(ch))
printf("\nCharacter is a Space\n");
else if(isdigit(ch))
printf("\nCharacter is a Digit\n");
else if(isalpha(ch))
printf("\nCharacter is a Alphabet and it's uppercase is %c\n",toupper(ch));
else if(isalnum(ch))
printf("\nCharacter is a Alphanumeric\n");
else
printf("\nCharacter is a %c\n",ch);
getch();
}
}



Write a program to accept any character from the keyboard and print the Ascii value of that character.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
char ch;
clrscr();
printf("*****Ascii value of Character entered*****\n\n");
printf("Enter any char : ");
scanf("%c",&ch);
printf("\nAscii value of %c is %d",ch,ch);
getch();
}



Write a C Programm showing File Operations

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

struct biodata{
int recno,age;
char name[20],sex;
float salary;
};


void main(){
void addData(void);
void delData(void);
void showAll(void);
void showRecord(void);
void alterData(void);

char choice;
clrscr();

while(1){
clrscr();
textcolor(YELLOW);
cprintf(" B I O - D A T A\r\n");
printf("\n\n*****CHOOSE YOUR CHOICE*****\n");
printf("1) ADD DATA\n");
printf("2) DELETE DATA\n");
printf("3) SHOW ALL\n");
printf("4) SHOW RECORD\n");
printf("5) ALTER DATA\n");
printf("6) Exit \n");
printf("Enter your choice : ");
fflush(stdin);
choice = getche();
switch(choice){
case '1' : //call add data
addData();
break;
case '2' : //call delete data
break;
case '3' : //call show all data
showAll();
break;
case '4' : //call show record
showRecord();
break;
case '5' : //call alter data
break;
case '6' :
case 27 : clrscr();
gotoxy(25,10);
_setcursortype(_NOCURSOR);
textcolor(LIGHTMAGENTA);
cprintf("THANKS FOR USING THIS SOFTWARE");
getch();
exit(1);
}
}

}


//Adding Record to File
void addData(){
FILE *fp;
struct biodata obj;
fp = fopen("biodata.txt","a+t");
clrscr();
printf("\n*****ADDING DATA*****\n");
printf("\nEnter Record No : ");
scanf("%d",&obj.recno);
printf("Enter Name : ");
fflush(stdin);
scanf("%s",obj.name);
printf("Enter age : ");
scanf("%d",&obj.age);
fflush(stdin);
printf("Enter Sex : ");
scanf("%c",&obj.sex);
printf("Enter Salary : ");
scanf("%f",&obj.salary);
fscanf(stdin,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
fprintf(fp,"%d %s %d %c %f",obj.recno,obj.name,obj.age,obj.sex,obj.salary);
fclose(fp);
}

void showRecord(){
FILE *fp;
struct biodata obj;
int rec;
long pos;
fp = fopen("biodata.txt","r");
clrscr();
printf("\n*****SHOWING SPECIFIC RECORD*****\n");
printf("\nEnter Record No : ");
scanf("%d",&rec);
pos = rec * sizeof(obj);
fseek(fp,pos,SEEK_SET);
if(feof(fp)==0)
printf("\n\nNO DATA FOUND\n");
else{
fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
printf("\n\n\tRecord No : %d\n",obj.recno);
printf("\tName : %s\n",obj.name);
printf("\tAge : %d\n",obj.age);
printf("\tSex : %c\n",obj.sex);
printf("\tSalary : %f\n",obj.salary);
}
getch();
fclose(fp);
}


void showAll(){
FILE *fp;
struct biodata obj;
int totrec,i;
fp = fopen("biodata.txt","r");
clrscr();
fseek(fp,0,SEEK_END);
totrec=ftell(fp)/sizeof(obj);
printf("\n*****SHOWING ALL RECORD*****\n");
printf("\n\nRecord_No\tName\t\tAge\tSex\tSalary\n\n");
printf("\n\n%d\n",totrec);
for(i=1;i<=totrec;i++){
fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
fprintf(stdout,"%-15d %-15s %-8d %-2c %10.2f\n",obj.recno,obj.name,obj.age,obj.sex,obj.salary);
}
getch();
fclose(fp);
}



Find out the sum of odd and even numbers between given range.

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
long range1,range2,totodd=0,toteven=0;
clrscr();

printf("*****SUM OF EVEN-ODD BETWEEN RANGE*****\n\n");
up:
printf("Enter Lower Range : ");
scanf("%ld",&range1);
printf("Enter Greater Range : ");
scanf("%ld",&range2);

if(range1 >= range2){
printf("\nImproper Input\n");
goto up;
}

while(range1 < range2){
if(range1 % 2 == 0)
toteven = toteven + range1;
else
totodd = totodd + range1;
range1++;
}

printf("\n\nSum of Even Range is %ld",toteven);
printf("\nSum of Odd Range is %ld",totodd);


getch();
}



Write a C Programm showing Encodeing Decoding Technique

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
char string[50],tmp[50];
int spcnt[50],i,j,c;
clrscr();
printf("Enter a string : ");
gets(string);

//encode logic
for(i=0;string[i];i++){
string[i]=string[i]+3;
}
textcolor(GREEN);
printf("\n");
cprintf("Encoded string is as follow : %s",string);

//decompressed logic
for(i=0;string[i];i++){
string[i]=string[i]-3;
}
textcolor(GREEN);
printf("\n");
cprintf("De-Encoded string is as follow : %s",string);
getch();
}



Write a prog. to convert digit into words.

*/
//Write a prog. to convert digit into words.
//eg : i/p:123 o/p : one hundered twenty three


/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include
void main(){
char init[27][12] = {" one "," two "," three ",
" four "," five "," six ",
" seven "," eight "," nine ",
" ten "," eleven "," twelve ",
" thirteen "," fourteen "," fifteen ",
" sixteen "," seventeen "," eighteen ",
" nineteen "," twenty "," thirty ",
" fourty "," fifty "," sixty ",
" seventy "," eight "," ninty "};
char sthou[20]="",shund[20]="",sval1[20]="",sval2[20]="",result[100]="";
int thou=0,hund=0,ten=0,temp=0,val1,val2,num,rem,c=0;

clrscr();
//USING COBOL LOGIC
printf("*****AMOUNT IN WORDS*****\n\n");
printf("Enter any value (upto 4 digits) : ");
scanf("%d",&num);
while(num>0){
rem = num%10;
c++;
if(c<=2)
temp = temp * 10 +rem;
else if(c==3)
hund = rem;
else if(c==4)
thou = rem;
num = num/10;
}
while(temp>0){ //as ten contains two digit so reverse it
rem = temp%10;
ten = ten * 10 + rem;
temp= temp/10;
}

if(thou>0){
strcpy(sthou,init[thou-1]);
strcat(sthou," thousand ");
strcat(result,sthou);
}

if(hund>0){
strcpy(shund,init[hund-1]);
strcat(shund," hundred ");
strcat(result,shund);
}

if(ten>0){
if(ten>20){
val1 = ten/10;
val2 = ten%10;
}
if(val1>0){
strcpy(sval1,init[val1+(18-1)]);
strcat(result,sval1);
}
if(val2>0){
strcpy(sval2,init[val2-1]);
strcat(result,sval2);
}
}
printf("\n\nAmount in word is as under \n");
printf("%s",result);

getch();
}



Write a C Programm to print date and time

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/


#include
#include

void main(){
time_t t;
time(&t);

printf("Today's date and time : %s",ctime(&t));
}



Write a menu driven c programm to display string in ascending and descending style

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/


#include
#include
void main(){
char str[]="C Programming";
int i,choice;
while(1){
clrscr();
printf("*****C Programming*****\n\n");
printf("1) Ascending style\n");
printf("2) Decending style\n");
printf("3) Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
printf("\n\n");
switch(choice){
case 1: //Ascending Style
for(i=0;str[i]!='\0';i++)
printf("%.*s\n",i,str);
printf("%.*s\n",i,str);
getch();
break;
case 2: //Decending Style
for(i=0;str[i]!='\0';i++);
while(i>0){
printf("%.*s\n",i,str);
i--;
}
getch();
break;
case 3: exit(1);
default : printf("\n\nInvalid choice\n\n");
getch();
}
}
}



Write a C Programm containing compress, de-compress logic

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
char string[50],tmp[50];
int spcnt[50],i,j,c;
clrscr();
printf("Enter a string : ");
gets(string);

//compress logic
for(i=0,c=0;string[i];i++){
if(string[i]==' '){
spcnt[c++]=i;
for(j=i;string[j];j++)
string[j]=string[j+1];
string[j]='\0';
}
}
spcnt[c]=-99;
textcolor(GREEN);
printf("\n");
cprintf("Compressed string is as follow : %s",string);

//decompressed logic
strcpy(tmp,"");
for(i=0,c=0;string[i];i++){
if(spcnt[c]==i){
tmp[i+c]=' ';
c++;
tmp[i+c]=string[i];
}
else{
tmp[i+c]=string[i];
}
}
tmp[i+c]='\0';
strcpy(string,tmp);
textcolor(RED);
printf("\n");
cprintf("De-Compressed string is as follow : %s",string);
getch();
}



Write a Programm to count words in a given string

*/
/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
char s[50],ch;
int i,c=0;
clrscr();
printf("Enter any string : ");
for(i=0;ch!='\n';i++){
ch=getchar();
s[i]=ch;
}
s[i]='\0';

for(i=0;s[i]!='\0';i++){
if(s[i]==' '){
c++;
while(s[i]==' ')
i++;
}
}
printf("\n\nTotal words are %d",c+1);
getch();
}



Write a C Programm to Print Chars

*/
/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
void main(){
int charcnt=0,dotcnt=0,commacnt=0,blankcnt=0,i;
char ch,str[125];
clrscr();
printf("*****String Manipulations*****\n\n");
printf("Enter a string ( 's' should be last char)\n\n");
scanf("%[^s]s",str);
printf("\n\nEntered String is \" %s \" \n",str);
for(i=0;str[i]!='\0';i++){
if(str[i]==' ')
blankcnt++;
else if(str[i]=='.')
dotcnt++;
else if(str[i]==',')
commacnt++;
}
charcnt=i;
printf("\n\nTotal Characters : %d",charcnt);
printf("\nTotal Blanks : %d",blankcnt);
printf("\nTotal Full stops : %d",dotcnt);
printf("\nTotal Commas : %d",commacnt);
getch();
}



Write a prog to find and print first N positive integers whose squares are palindormes.

*/
/*Write a prog to find and print first N positive integers whose
squares are palindormes.
eg: 11^2 = 121, 26^2 = 676.
*/



/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include

void main(){
int n;
void pelind(int);
clrscr();
printf("Enter Value of N : ");
scanf("%d",&n);
pelind(n);
getch();
}

void pelind(int n){
int cnt=0,i,rev,rem,tmpnum,c;
printf("\n\n****N Pelindrome Squares are *****\n");
for(i=1;cnt!=n;i++){
//square
c=i*i;
tmpnum=c;
rev=0;
while(c>0){
rem=c%10;
rev=rev*10+rem;
c=c/10;
}
if(tmpnum==rev)
{
cnt++;
printf("N is %d --> Pelindrome square is %d\n",i,tmpnum);
}
}
}



Powered by Wufoo