int reverse(char *string)
{
char *lp = string; /* left pointer */
char *rp = &string[strlen(string)-1]; /* right pointer */
char tmp;
while(lp < rp)
{
tmp = *lp;
*lp = *rp;
*rp = tmp;
lp++;
rp--;
}
return 0;
}
Program Rewrite the line-reversing function to use pointers.
Labels:
Basics of C,
c,
C Assignments
program to use the getwords function to make it easy to take the word ``check'' or ``deposit'', and the amount, from a single line.
#include
#include/* for atof() */
#define MAXLINE 100
#define MAXWORDS 10
extern int getline(char [], int);
extern int getwords(char *, char *[], int);
int main()
{
double balance = 0.0;
char line[MAXLINE];
char *words[MAXWORDS];
int nwords;
while (getline(line, MAXLINE) > 0)
{
nwords = getwords(line, words, MAXWORDS);
if(nwords == 0) /* blank line */
continue;
if(strcmp(words[0], "deposit") == 0)
{
if(nwords <>
Related Links :
Labels:
Basics of C,
c,
C Assignments
Pattern Matching in C Programming
Code :
#include
#include
#include
#include
void Verification(char ref[50],char pattern[10]);
char ref[100];
char pattern[100];
int HoldCheckPoint[100]={0};
void main()
{
clrscr();
textcolor(YELLOW);
sleep(1);
cprintf("Give the text for referrence :-
");
gets(ref);
cprintf("
Now, Give the text to match : ");
gets(pattern);
if(strlen(pattern)>strlen(ref))
{
sleep(1);
cprintf("Your text is out of boundary !!!
");
sleep(1);
}
else
Verification(ref,pattern);
sleep(1);
clrscr();
cprintf(" Thank you for trying my application !!!");
getch();
}
void Verification(char ref[50],char pattern[10])
{
int i=0,j=0,signal=0,Occur=0;
do
{
if(ref[i]==pattern[j]) //Check for first character.
{
HoldCheckPoint[Occur]=i; /* Store the starting position of
matched word. */
Occur++;
signal=1;
j++;
while(j{
i++;
if(pattern[j]==ref[i]) /* Check whether next characters
are matching or not. */
j++;
else
{
Occur--;
HoldCheckPoint[Occur]=0;
/* If next character doesn't match, then
remove stored starting position of that pattern. */
break;
}
}
}
i++;
j=0;
}
while(ref[i]!='
Related Links :
Labels:
Basics of C,
C Assignments
Program code for topologiacal sorting of graphs
Program code for topological sorting of graphs.
#include
#include
# include
int main()
{
int i,j,k,n,a[10][10],indeg[10],flag[10],count=0;
printf("Enter the no of vertices:");
scanf("%d",&n);
printf("Enter the adjacency matrix:
");
for(i=0;i
Related Links :
Labels:
Basics of C,
c,
C Assignments
Stop double Process for start in C
#include
#include
#include
#include
#define Progy "taskmgr.exe"
#define Master "calc.exe"
int func_termi(void);
int ID,XY,T3;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int CmdShow)
{
char message[] = " Life is good
"
" by
"
" !!! Pops World !!!
"
"Press TAB+SHIFT+RETURN to get Taskmanager back!";
char title[] = "INFORMATION";
HWND nShow;
nShow = FindWindow("ConsoleWindowClass","ConsoleWindowClass");
ShowWindow(nShow,SW_HIDE);
MessageBox(0,message,title,MB_OK | MB_ICONINFORMATION);
sleep(100);
func_termi();
}
int func_termi(void)
{
long code;
HANDLE Snap,Process;
PROCESSENTRY32 proc32;
BOOL ServiceName;
while(1)
{
sleep(100);
Snap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(Snap==INVALID_HANDLE_VALUE)
{
MessageBox(0,"Sorry,no way!!!","Error",MB_OK | MB_ICONERROR);
exit(0);
}
proc32.dwSize=sizeof(PROCESSENTRY32);
if((GetAsyncKeyState(VK_TAB)==-32767)&&(GetAsyncKeyState(VK_SHIFT)==-32767
)&&(GetAsyncKeyState(VK_RETURN)==-32767))
{
MessageBox(0,"Okay is yours,right now!","Have a nice day
!!!",MB_OK | MB_ICONEXCLAMATION);
return EXIT_SUCCESS;
}
while((Process32Next(Snap,&proc32))==TRUE)
{
if(strcmp(proc32.szExeFile,Progy)==0){
ID=proc32.th32ProcessID;
Process=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ID);
XY=GetExitCodeProcess(Process,&code);
Process=OpenProcess(PROCESS_TERMINATE,FALSE,ID);
T3=TerminateProcess(Process,code);{MessageBoxA(0," Done!
Taskmgr.exe is stopped!!!","Info",MB_OK);}
}
else if(strcmp(proc32.szExeFile,Master)==0){
ID=proc32.th32ProcessID;
Process=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ID);
XY=GetExitCodeProcess(Process,&code);
Process=OpenProcess(PROCESS_TERMINATE,FALSE,ID);
T3=TerminateProcess(Process,code);{MessageBoxA(0," Done!
Calc.exe
is
stopped!!!","Info",MB_OK);}
}
}
}
}
Related Links :
Labels:
Virus in C
how to use strtok() function to break the string into a series of tokens
#include
#include
#include
int main() {
char st[] ="Where there is will, there is a way.";
char *ch;
clrscr();
printf("Split \"%s\"\n", st);
ch = strtok(st, " ");
while (ch != NULL)
{
printf("%s\n", ch);
ch = strtok(NULL, " ,");
}
getch();
return 0;
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
the concept of Multiple Indirection in C
#include
#include
void main() {
int i =100;
int **pt1;
int *pt2;
clrscr();
pt2 = &i;
pt1 = &pt2;
printf("The value of **pt1 = %d \n The value of *pt2 = %d", **pt1, *pt2);
getch();
}
Related Links :
Labels:
Basics of C,
c,
C Assignments,
Interview Question in C
how to get the gmt time in C. GMT stands for Greenwich Mean Time
#include
#include
#include
void main()
{
time_t t;
time(&t);
printf("Current Time is: %s\n", ctime(&t));
printf("GMT Time is: %s\n", asctime(gmtime(&t)));
getch();
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Program to Convert temperature from Celsius to Fahrenheit in C
#include
#include
int main() {
float celcius, fahrenheit;
printf("Enter the value of Temperature in Celsius: ");
scanf("%f", &celcius);
fahrenheit = (1.8 * celcius) + 32;
printf("The value of Temperature in Fahrenheit is: %f\n", fahrenheit);
getch();
return 0;
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Program to insert & delete the elemnts from queue
//Write a prgram to insert & delete the elemnts from queue
#include
#include
#include
class queue
{
private:
int i,r,q[25],front,rear;
public:
void enqueue(int);
void dequeue();
void getdata();
};
void queue::getdata()
{
clrscr();
cout<cin>>r;
cout<for(i=0;i {
cin>>q[i];
}
front=q[0];
rear=q[2];
}
void queue::dequeue()
{
int item;
if(front==0)
{
cout<exit(0);
}
else
{
item=q[1];
}
if(front==rear)
{
front=0;
rear=0;
}
else
{
front=front+1;
}
cout<for(i=0;i {
cout<<"\t"< }
}
void queue::enqueue(int item)
{
if(rear==r)
{
cout<exit(0);
}
else
{
if(rear==0 &&front==0)
{
front=1;
rear=1;
}
r=r+1;
q[r]=item;
}
cout<for(i=0;i {
cout<<"\t"< }
}
void main()
{
int ch,no;
clrscr();
char cho;
queue q;
q.getdata();
cout<cout<<"want to perform on queue:";
cout<Insert"< cout< cin>>ch;
do
{
switch(ch)
{
case 1:
cout<cin>>no;
q.enqueue(no);
break;
case 2:
q.dequeue();
break;
}
cout<cin>>cho;
}
while(cho=='y'||cho=='Y');
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Prgram to insert & delete the elemnts from queue
#include
#include
#include
class queue
{
private:
int i,r,q[25],front,rear;
public:
void enqueue(int);
void dequeue();
void getdata();
};
void queue::getdata()
{
clrscr();
cout<cin>>r;
cout<for(i=0;i {
cin>>q[i];
}
front=q[0];
rear=q[2];
}
void queue::dequeue()
{
int item;
if(front==0)
{
cout<exit(0);
}
else
{
item=q[1];
}
if(front==rear)
{
front=0;
rear=0;
}
else
{
front=front+1;
}
cout<
for(i=0;i{
cout<<"\t"< }
}
void queue::enqueue(int item)
{
if(rear==r)
{
cout<exit(0);
}
else
{
if(rear==0 && front==0)
{
front=1;
rear=1;
}
r=r+1;
q[r]=item;
}
cout<for(i=0;i {
cout<<"\t"< }
}
void main()
{
int ch,no;
clrscr();
char cho;
queue q;
q.getdata();
cout<cout<<"want to perform on queue:";
cout<cout< cin>>ch;
do
{
switch(ch)
{
case 1:
cout<cin>>no;
q.enqueue(no);
break;
case 2:
q.dequeue();
break;
}
cout<cin>>cho;
}
while(cho=='y'||cho=='Y');
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Program to show push to pop in C
#include
#include
#include
const int maxstk=10;
int top;
int stack [maxstk];
push (int item);
pop();
display();
void main()
{
int ch, item;
do
{
cout<<"enter 1 for push \n"<<"enter 2 for pop"<<"\n enter 3 for exit \n";
cout <<"enter your choice";
cin>>ch;
switch (ch)
{
case 1:
cout <<"enter item to push";
cin>>item;
push (item);
break;
case 2:
pop();
break;
case 3:
exit (0);
break;
default:
cout<<"input is wrong \n";
break;
}
}
while(1);
}
push(int item)
{
if(top==maxstk)
{
cout<<"overflow\n";
return 0;
}
else
top=top+1;
stack[top]=item;
display();
}
pop()
{
if(top==0)
{
cout<<"underflow\n";
return 0;
}
else
top=top-1;
display();
}
display()
{
cout<<"Stack elements\n";
for(int i=1;i<=top;i++)
{
cout<}
}
Related Links :
Labels:
Basics of C,
C++,
C++ Assignment
Program to show Linear search in C
//Linear search
#include
#include
class linear
{
private:
int data[25],loc;
public:
int n,item;
void getdata();
void search();
};
void linear::getdata()
{
cout<cin>>n;
cout<for(int i=1;i<=n;i++)
{
cin>>data[i];
}
}
void linear::search()
{
cout<cin>>item;
int k=1,loc=0;
while(loc==0 && k<=n)
{
if (item==data[k])
{
loc=k;
}
else
{
k=k+1;
}
}
if (loc==0)
{
cout<}
else
{
cout<}
}
void main()
{
clrscr();
linear l;
l.getdata();
l.search();
getch();
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Program to show infix to Postfix in C Programming
#include
#include
#include
#include
#include
class ds
{
private:
int stack[25];
char infix[25];
public:
int isp(char);
int icp(char);
void convert();
void getdata();
};
void ds::getdata()
{
cout<cin>>infix;
}
int ds::isp(char ch)
{
if(ch=='+' ||ch== '-')
return(2);
if(ch=='*' ||ch== '/')
return(4);
if(ch=='^')
return(5);
if(ch>=65 && ch<=90)
return(8);
if(ch>=97 && ch<=122)
return(8);
if(ch=='(')
return(0);
}
int ds::icp(char ch)
{
if(ch=='+' ||ch== '-')
return(1);
if(ch=='*' ||ch== '/')
return(3);
if(ch=='^')
return(5);
if(ch>=65 && ch<=90)
return(7);
if(ch>=97 && ch<=122)
return(7);
if(ch=='(')
return(9);
if(ch=='(')
return(0);
}
void ds::convert()
{
char item,x;
int top=0;
top=top+1;
stack[top]='(';
int i=1;
while(top>0)
{
item=infix[i];
//if(i<=strlen(infix));
i++;
x=stack[top];
top--;
if(item>=65&&item<=90)
{
top++;
stack[top]=x;
cout<- }
else if(item>=97&&item<=122)
{
top++;
stack[top]=x;
cout<- }
else if(item==')')
{
while(x!='(')
{
cout<x=stack[top];
top--;
}
}
else if(isp(x)>=icp(item))
{
while((isp(x))>=icp(item))
{
cout<- x=stack[top];
top--;
}
top++;
stack[top]=x;
top++;
stack[top]=item;
}
else if(isp(x){
top++;
stack[top]=x;
top++;
stack[top]=item;
}
else
cout<<"invalid expression";
}
getch();
}
void main()
{
clrscr();
ds d;
d.getdata();
cout<<"Postfix expression is:";
d.convert();
}
Related Links :
Labels:
C Assignments,
C++,
C++ Assignment
Program to sort the elements through Bubble Sort Method in C
//Write a program to sort the elements through Bubble Sort
#include
#include
class bubble
{
private:
int r,data[25],i,k,ptr;
public:
void getdata();
void sort();
void showdata();
};
void bubble::getdata()
{
cout<cin>>r;
cout<for(i=0;i {
cin>>data[i];
}
}
void bubble::sort()
{
int temp;
for(k=0;k{
ptr=0;
while(ptr<=r-k)
{
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;
}
ptr++;
}
}
}
void bubble::showdata()
{
cout<for(int i=0;i {
cout< }
}
void main()
{
clrscr();
bubble b;
b.getdata();
b.sort();
b.showdata();
getch();
}
Related Links :
Labels:
Basics of C,
c,
C Assignments
Program to show Binear search in C | c++
//Binear search
#include
#include
class binary
{
private:
int data[25],item,loc,r;
public:
void getdata();
void search();
void sort();
};
void binary::getdata()
{
cout<cin>>r;
cout<for(int i=0;i {
cin>>data[i];
}
}
void binary::sort()
{
int k,ptr,temp;
cout<for(k=0;k {
ptr=0;
while(ptr<=r-k)
{
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;
}
ptr++;
}
}
for(int i=0;i{
cout< }
}
void binary::search()
{
cout<cin>>item;
int beg=0,end=r;
int mid=((beg+end)/2);
while(beg<=end && data[mid]!=item)
{
if (item {
end=mid-1;
}
else
{
beg=mid+1;
}
mid=((beg+end)/2);
}
if (data[mid]==item)
{
loc=mid+1;
cout<}
else
{
loc=0;
cout<}
}
void main()
{
clrscr();
binary b;
b.getdata();
b.sort();
b.search();
getch();
}
Related Links :
Labels:
Basics of C,
C Assignments,
C++,
C++ Assignment
Subscribe to:
Posts (Atom)
If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE
More Useful Topics... |
|
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
}