The main file i'll call it a4.c to the lack of a better name,(actually it was my fourth assignemnt,or to quote the bard "What's in a name ?")
Make a header file by adding
#include<stdio.h>
and save it as head.h The motive here is to follow a good programming practice where we keep all the headers in a single file and all functions(some if not all,as the case is) in another file and incorporate them into the main file
Though i can no way compete against a simpler explanation for make files ,refer this link
save it as mf
all: a4
a4: a4.o fu.o
gcc a4.o -o a4
a4.o: a4.c head.h
gcc -c -g a4.c
fu.o: fu.c
gcc -c -g fu.c
clean:
rm -rf *o a4
So in all we have a main file a4.c provided here,a function fu.c provided here
and the makefile mf
to run execute " make -f mf "
and " ./a4 " in terminal
..............................................................................................................
#include"head.h"
#include"fu.c"
/*! \mainpage Welcome to the much awaited card game
*
* \section welcome Introducing a program for your gaming pleasure please do check the files
*
* \image html index.jpeg
*
* \section install To run you need the ubiquitous
* <a href="en.wikipedia.org/wiki/Linux"> linux</a> OS and the
* <a href="en.wikipedia.org/wiki/GNU_Compiler_Collection"> gcc</a> <a href="en.wikipedia.org/wiki/Compiler"> compiler </a>
*\section usage Follow the specified steps to get it going
* \subsection step1 Step 1:Enter the list of cards in the a1.txt file one after the other ,The desired card is entered at third slot
* \subsection step2 Step 2:Enter the user desired card statement into the b1.txt parse the ending with a '$'
* \subsection step3 Step 3:Run the make file and execute the .exe thus generated and you are good to go
*
*
*/
/*!
* \brief program to implementation of mathematical card spell out trick in c
* \details The program accepts the set of cards in a certain order from a file named a1.txt and also gets the user choice for the card.
it then based on the user choice of card realters the original order of cards read from file a1.txt to generate the list of card in order dictated by the program such that the card arrives at the fifth slot as the case demands
* \author Vinayak
* \image html images.jpeg
* \version 1.0
* \date 2-2011
* \pre First initialize the a1.txt and b1.txt files.
* \bug Altering the file format may provide unknown results.
* \warning Improper use can crash your application
* \copyright Public License.
* \see fu.c
*
*
*/
void main()
{char a[9],c[20],d[9],tmp1[9],tmp2[9];
char b[9],co[3];
int i=0,j=0,k=0,l=0;
char t;
FILE *f;
f=fopen("a1.txt","rt");
if(f==NULL)
{printf("cant open file of cards");
exit(0);
}
//Read from the file the list of cards
while(t=fgetc(f))
{if(t==EOF)
break;
c[i]=t;i++;
}
i=0;
/*store the list of cards into two single dimension arrays if needed a two *dimension array can be used,as well.
*/
while(c[l]!='\0' && l<26 && k<=8 && j<=8)
{
if(c[l]!=10 && c[l+1]!=10)
{a[j]=c[l];
l++;
d[j]=c[l];
j++;}
l++;
}
printf("The cards before you are\n");
for(l=0;l<9;l++)
printf("%c(%c)\n",a[l],d[l]);
l=0;
fclose(f);
//It now reads user choice of cards from another file
f=fopen("b1.txt","rt");
if(f==NULL)
{printf("cant open file of your input");
exit(0);
}
i=0;
while(t=fgetc(f))
{if(t==EOF)
break;
c[i]=t;i++;
}
l=0;
printf("your lucky call is\n");
while(c[l]!='$')
{
printf("%c ",c[l]);
l++;
}
/*Calculate the legth of each word demarcated by space ,an additional *delimiter '$' is used at the end for convienience.The calculated word *length is stored in an array
*/
i=0;k=0;j=0;
for(;k<3;k++)co[k]=0;
k=0;l=0;
while(c[i]!='$' )
{
if(c[i]==32 )
{
l++;
}
else co[l]+=1;
i++;
}
/*Perform three iterations each time using the length of respective word *the card array content is realtered as per the rule
*/
fu(a,d,co);
//The result is displayed for the users viewing pleasure
printf("\nThe final results for The bet\n");
for(i=0;i<9;i++)
{
printf(" %c(%c) \n ",a[i],d[i]);
}
//The end!!!!!!!
return;
}
Make a header file by adding
#include<stdio.h>
and save it as head.h The motive here is to follow a good programming practice where we keep all the headers in a single file and all functions(some if not all,as the case is) in another file and incorporate them into the main file
Though i can no way compete against a simpler explanation for make files ,refer this link
save it as mf
all: a4
a4: a4.o fu.o
gcc a4.o -o a4
a4.o: a4.c head.h
gcc -c -g a4.c
fu.o: fu.c
gcc -c -g fu.c
clean:
rm -rf *o a4
So in all we have a main file a4.c provided here,a function fu.c provided here
and the makefile mf
to run execute " make -f mf "
and " ./a4 " in terminal
..............................................................................................................
#include"head.h"
#include"fu.c"
/*! \mainpage Welcome to the much awaited card game
*
* \section welcome Introducing a program for your gaming pleasure please do check the files
*
* \image html index.jpeg
*
* \section install To run you need the ubiquitous
* <a href="en.wikipedia.org/wiki/Linux"> linux</a> OS and the
* <a href="en.wikipedia.org/wiki/GNU_Compiler_Collection"> gcc</a> <a href="en.wikipedia.org/wiki/Compiler"> compiler </a>
*\section usage Follow the specified steps to get it going
* \subsection step1 Step 1:Enter the list of cards in the a1.txt file one after the other ,The desired card is entered at third slot
* \subsection step2 Step 2:Enter the user desired card statement into the b1.txt parse the ending with a '$'
* \subsection step3 Step 3:Run the make file and execute the .exe thus generated and you are good to go
*
*
*/
/*!
* \brief program to implementation of mathematical card spell out trick in c
* \details The program accepts the set of cards in a certain order from a file named a1.txt and also gets the user choice for the card.
it then based on the user choice of card realters the original order of cards read from file a1.txt to generate the list of card in order dictated by the program such that the card arrives at the fifth slot as the case demands
* \author Vinayak
* \image html images.jpeg
* \version 1.0
* \date 2-2011
* \pre First initialize the a1.txt and b1.txt files.
* \bug Altering the file format may provide unknown results.
* \warning Improper use can crash your application
* \copyright Public License.
* \see fu.c
*
*
*/
void main()
{char a[9],c[20],d[9],tmp1[9],tmp2[9];
char b[9],co[3];
int i=0,j=0,k=0,l=0;
char t;
FILE *f;
f=fopen("a1.txt","rt");
if(f==NULL)
{printf("cant open file of cards");
exit(0);
}
//Read from the file the list of cards
while(t=fgetc(f))
{if(t==EOF)
break;
c[i]=t;i++;
}
i=0;
/*store the list of cards into two single dimension arrays if needed a two *dimension array can be used,as well.
*/
while(c[l]!='\0' && l<26 && k<=8 && j<=8)
{
if(c[l]!=10 && c[l+1]!=10)
{a[j]=c[l];
l++;
d[j]=c[l];
j++;}
l++;
}
printf("The cards before you are\n");
for(l=0;l<9;l++)
printf("%c(%c)\n",a[l],d[l]);
l=0;
fclose(f);
//It now reads user choice of cards from another file
f=fopen("b1.txt","rt");
if(f==NULL)
{printf("cant open file of your input");
exit(0);
}
i=0;
while(t=fgetc(f))
{if(t==EOF)
break;
c[i]=t;i++;
}
l=0;
printf("your lucky call is\n");
while(c[l]!='$')
{
printf("%c ",c[l]);
l++;
}
/*Calculate the legth of each word demarcated by space ,an additional *delimiter '$' is used at the end for convienience.The calculated word *length is stored in an array
*/
i=0;k=0;j=0;
for(;k<3;k++)co[k]=0;
k=0;l=0;
while(c[i]!='$' )
{
if(c[i]==32 )
{
l++;
}
else co[l]+=1;
i++;
}
/*Perform three iterations each time using the length of respective word *the card array content is realtered as per the rule
*/
fu(a,d,co);
//The result is displayed for the users viewing pleasure
printf("\nThe final results for The bet\n");
for(i=0;i<9;i++)
{
printf(" %c(%c) \n ",a[i],d[i]);
}
//The end!!!!!!!
return;
}
No comments:
Post a Comment