kathrotiyanimesh
BAN USER#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
fp=fopen("fileprog1.c","r");
if(fp==NULL)
{
printf("error!\n");
exit(1);
}
char c;
while(fread(&c,sizeof(c),1,fp)!=NULL)
{
printf("%c",c);
}
fclose(fp);
}
- kathrotiyanimesh July 19, 2013int xstrcmp(const char *p,const char *q)
{
while(*p++==*q++ && *p);
return *(--p)-*(--q);
}
//Tic Toc game simulation..........
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
char bord[3][3]={{'1','2','3'},{'4','5','6'},{'7','8','9'}};
char win_status='\0',turn='\0';
char win_check(char);
void add_on_board(char);
void print(void);
void main()
{
printf("Welcome to Tic Toc Game\n");
printf("Rule-1: Two players, A and B.\n");
printf("Rule-2: A has 'X' and B has 'O' piece on board. \n");
printf("Initial status of board\n");
print();
char e='\0',f;
int n=1;
printf("ready to play?(y/n):");
scanf("%c",&f);
f=getchar();
while(win_status=='\0' && n<5)
{
system("clear");
printf("For A ==> X\nFor B ==> O\n\n");
print();
if(win_status=='\0')
{
turn='A';
printf("A 's turn: press number:");
fflush(stdin);
//sleep(3);
scanf("%c",&e);
f=getchar();
//scanf("%c",&f);
add_on_board(e);
win_status=win_check('X');
print();
}
if(win_status=='\0')
{
turn='B';
printf("B 's turn: press number:");
fflush(stdin);
scanf("%c",&e);
f=getchar();
add_on_board(e);
win_status=win_check('O');
print();
}
n++;
}
switch(win_status)
{
case 'A':
printf("Winner is ---A---\nCongrates\n");
break;
case 'B':
printf("Winner is ---B---\nCongrates\n");
break;
default:
printf("Match draw!\n");
}
}
char win_check(char p)
{
char temp[3]={'\0'};
int i=0,j=0,k=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++) temp[j]=bord[i][j];
for(k=0;k<3;k++) if(temp[k]!=p) break;
if(k==3) return (p=='X'?'A':'B');
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++) temp[j]=bord[j][i];
for(k=0;k<3;k++) if(temp[k]!=p) break;
if(k==3) return (p=='X'?'A':'B');
}
for(i=0;i<3;i++) temp[i]=bord[i][i];
for(k=0;k<3;k++) if(temp[k]!=p) break;
if(k==3) return (p=='X'?'A':'B');
for(i=0;i<3;i++) temp[i]=bord[i][2-i];
for(k=0;k<3;k++) if(temp[k]!=p) break;
if(k==3) return (p=='X'?'A':'B');
return '\0';
}
void add_on_board(char c)
{
int i=0,j=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(bord[i][j]==c)
{
bord[i][j]=(turn=='A'?'X':'O');
return;
}
}
}
}
void print(void)
{
int i=0,j=0;
printf("\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%-4c",bord[i][j]);
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
char s[]="nimesh";
char *str="nimesh";
printf("s=%s\n",s);
printf("str=%s\n",str);
s[1]='a'; // this works fine
str[1]='a'; // this gives segmentation fault as it is constant string and stored in Read only area....
printf("s=%s\n",s);
printf("str=%s\n",str);
}
- kathrotiyanimesh May 28, 2013not 4 but 3, as if we find cyclomatic complexity of the graph then it is 3.
so total 3 test cases for 2 simple if with simple conditions.......
very good solution......
- kathrotiyanimesh May 15, 2013first, start pre-order traversal of tree, when you visit node decrement count by 1,if count==0 return that element,,,,,initialize count by 'n'.
- kathrotiyanimesh May 15, 2013
}
- kathrotiyanimesh July 19, 2013