예제 #1
0
void main(void)
 {
   int a, b, c;

   cprintf("Type 3 integer values and press Enter\r\n");
   cscanf("%d %d %d", &a, &b, &c);
   cprintf("The values entered were %d %d %d\r\n", a, b, c);
 }
예제 #2
0
void main( void )
{
    int errFlag[NUMFUNC];
    char *funcName[] = { "cgets()",
                         "cprintf()",
                         "cputs()",
                         "getche()",
                         "getch()",
                         "kbhit()",
                         "putch()",
                         "ungetch()",
                         "cscanf()" };
    char buffer[83], str1[80], str2[80];
    int num1, num2;
    double fnum1;

    buffer[0] = 11;
    dispStr( "Start of cgets()...\r\n" );
    sprintf( str1, "Note: buffer[0] = %d.\r\n", buffer[0] );
    dispStr( str1 );
    dispStr( "Type the following (no quotes): \"12345\"\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be any CR/LF contained in the string.\r\n" );
    errFlag[0] = strcmp( &buffer[2], "12345" ) != 0 ? TRUE : FALSE;
    dispStr( "Type the following (no quotes): \"123456789012345\"\r\n" );
    dispStr( "Note: only the first 10 characters should be allowed.\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string (first 10 characters) " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be any CR/LF contained in the string.\r\n" );
    if( errFlag[0] == FALSE ) {
        errFlag[0] = strcmp( &buffer[2], "1234567890" ) != 0 ? TRUE : FALSE;
    }
    dispStr( "Type the following: \"\" (just press <Enter>)\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be anything contained in the string.\r\n" );
    if( errFlag[0] == FALSE ) {
        errFlag[0] = strcmp( &buffer[2], "" ) != 0 ? TRUE : FALSE;
    }
    dispStr( "End of cgets() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cprintf()...\r\n" );
    dispStr( "Compare the following:\r\n" );
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "|-Start-> Testing <-|\r\n" );
    dispStr( "                     |-> 12345.67 <-End-|\r\n" );
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "with the following. " );
    dispStr( "If cprintf() is ok,\r\nthey should be identical:\r\n" );
    strcpy( buffer, "Testing" );
    fnum1 = 12345.666;
    dispStr( "-----------------------------------------\r\n" );
    cprintf( "|-Start-> %s <-|\n|-> %8.2lf <-End-|\n\r",buffer, fnum1);
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "Note: there shouldn't be any blank lines in between.\r\n" );
    dispStr( "Does cprintf() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[1] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of cprintf() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cputs()...\r\n" );
    dispStr( "You should see \"|-->Testing<--|\" on next line:\r\n" );
    strcpy( buffer, "|-->" );
    cputs( buffer );
    strcpy( buffer, "Testing" );
    cputs( buffer );
    strcpy( buffer, "<--" );
    cputs( buffer );
    dispStr( "|\r\nDoes cputs() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[2] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of cputs() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of getche()...\r\n" );
    dispStr( "Press the key 'a':\r\n" );
    num1 = getche();
    dispStr( "\r\nthe character should have been echoed back.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d)\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[3] = num1 != 'a' ? TRUE : FALSE;
    dispStr( "End of getche() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of getch()...\r\n" );
    dispStr( "Press the key 'b':\r\n" );
    num1 = getch();
    dispStr( "\r\nNothing should have been echoed back.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d)\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[4] = num1 != 'b' ? TRUE : FALSE;
    dispStr( "End of getch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of kbhit()...\r\n" );
    dispStr( "Waiting for user to press the key 'c' (looping):\r\n" );
    for( ; !kbhit(); );
    num1 = getch();
    dispStr( "getch() was used to obtain the character pressed.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d).\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[5] = num1 != 'c' ? TRUE : FALSE;
    dispStr( "End of kbhit() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of putch()...\r\n" );
    dispStr( "You should see:\r\n--\r\nH\r\n i\r\n--\r\nin the next four lines:\r\n" );
    dispStr( "--\r\n");
    num1 = 'H';
    num2 = 'i';
    putch( num1 );
    putch( '\n' );
    putch( num2 );
    putch( '\r' );
    putch( '\n' );
    dispStr( "--\r\n");
    dispStr( "Does putch() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[6] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of putch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of ungetch()...\r\n" );
    dispStr( "Note: getch() will be used to get " );
    dispStr( "a character from the console.\r\n" );
    dispStr( "      Ignore this test if getch() is disfunctional.\r\n" );
    dispStr( "Waiting for user to press the key 'd':\r\n" );
    num1 = getch();
    sprintf( buffer, "Received the key ->%c<-\r\n",num1 );
    dispStr( buffer );
    num2 = ungetch( num1 );
    sprintf( buffer, "The character ->%c<- has been ungetch()'ed.\r\n", num1 );
    dispStr( buffer );
    dispStr( "Now, the character will once again be obtained using ");
    dispStr( "getch().\r\n" );
    num2 = getch();
    sprintf( buffer, "The character above ->%c<- was the one ", num2 );
    dispStr( buffer );
    dispStr( "being pushed back.\r\n" );
    if( num1 != num2 || num1 != 'd' ) {
        errFlag[7] = TRUE;
    } else {
        errFlag[7] = FALSE;
    }
    dispStr( "End of ungetch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cscanf()...\r\n" );
    dispStr( "Input the following: 'test1 test2 1234 1.45'\r\n" );
    cscanf( "%s %s %d %lf", str1, str2, &num1, &fnum1 );
    getch();    // Discard the ending character that's left over
    dispStr( "\r\nThis is what you entered:\r\n" );
    sprintf( buffer, "\"%s, %s, %d, %4.2lf\"\r\n", str1, str2, num1, fnum1 );
    dispStr( buffer );
    if( strcmp( str1, "test1" ) != 0 || strcmp( str2, "test2" ) != 0 ||
        num1 != 1234 || fnum1 != 1.45 ) {
        errFlag[8] = TRUE;
    } else {
        errFlag[8] = FALSE;
    }
    dispStr( "End of cscanf() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "End of all tests.\r\n\r\n" );
    for( num1 = 0, num2 = FALSE; num1 < NUMFUNC; ++num1 ) {
        if( errFlag[num1] == TRUE ) {
            sprintf( buffer, "%s\r\n", funcName[num1] );
            dispStr( buffer );
            num2 = TRUE;
        }
    }
    dispStr( "\r\n" );
    if( num2 == TRUE ) {
        dispStr( "This program has found unexpected result(s) when testing" );
        dispStr( "\r\nthe above function(s). Reasons could be that the\r\n" );
        dispStr( "function(s) being used in the test(s) might have" );
        dispStr( " problems.\r\n" );
    } else {
        dispStr( "All the functions seem to pass the test!\r\n" );
    }
}
예제 #3
0
void main()
{
int i,no,j,z;
textattr(1<<4|14);
clrscr();
cprintf("Asume A Word!\n\n\rStep 1:\n\r=======\n\rTabel 1:\n\n\r");
textattr(1<<4|12);
for(i=0;i<5;i++)
cprintf("%d ",i+1);
textattr(7<<4);
for(i=0;i<30;i++)
 {
 if(i%5==0)
 printf("\n");
 cprintf("%c ",arr[i]);
 }
textattr(1<<4|14);
gotoxy(1,15);
cprintf("\n\n\rEnter Total Number of letters in word:");
cscanf("%d",&no);
cprintf("                                            ");
for(i=0;i<no;i++)
{
gotoxy(1,15);
cprintf("\n\n\rEnter Letter %d Coloumn number:",i+1);
scanf("%d",&pos1[i]);
pos1[i]-=1;
}
clrscr();
cprintf("Step 2:\n\rTabel 2:\n\r");
textattr(1<<4|12);
for(i=0;i<6;i++)
cprintf("%d ",i+1);
textattr(7<<4);
for(i=0;i<no;i++)
 {
 printf("\n");
 for(j=pos1[i];j<30;j+=5)
    cprintf("%c ",arr[j]);
 }
textattr(1<<4|14);
for(i=0;i<no;i++)
{
gotoxy(1,15);
cprintf("\n\n\rEnter the  %d Letter's Coloumn number:",i+1);
scanf("%d",&pos2[i]);
pos2[i]-=1;
}
clrscr();
gotoxy(30,13);
cprintf("We Got U! ");
gotoxy(30,15);
cprintf("SURPRISED!");
textcolor(WHITE+BLINK);
gotoxy(30,14);
for(i=0;i<no;i++)
{
cprintf("%c",arr[pos2[i]*5+pos1[i]]);
}
textcolor(YELLOW+BLINK);
cprintf("\n\n\n\n\n\n\n\n\rPress Esc To Exit...");
while(getch()!=27);
}
예제 #4
0
int move_edit()
{
char *ptr=0;
//const char *r=ptr;
int a=71,i,j,flag=1,k=15,row=0,col=0,b[9][9];
//intializing the grid:
       //	char c;
	for(i=0;i<9;i++)
	{
		for(j=0;j<9;j++)
		b[i][j]=-1;
	}

	i=167; j=132;
	b[0][0]=0;
	settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
	while(a!=27)
{
	setcolor(k);
	if(flag==1)
	outtextxy(i,j,"-");
	k=0;
	a=getch();
	if(a==77)
	{	flag=1;
		if(col!=8)
		{	++col;
			i=i+20;
		}
		if(b[row][col]==-1)
			b[row][col]=0;
		k=15;
	}
	else if(a==80)
	{	flag=1;
		if(row!=8)
		{	++row;
			j=j+20;
		}
		if(b[row][col]==-1)
			b[row][col]=0;
		k=15;
	}
	else if(a==75)
	{	flag=1;
		if(col!=0)
		{	--col;
			i=i-20;
		}
		if(b[row][col]==-1)
			b[row][col]=0;
		k=15;
	}
	else if(a==72)
	{	flag=1;
		if(row!=0)
		{	--row;
			j=j-20;
		}
		if(b[row][col]==-1)
			b[row][col]=0;
		k=15;
	}
	else if(a==82)
	{       if(b[row][col]<1)
		{
			flag=0;
			textcolor(0);
			cscanf("%c",ptr);
		       //	ptr=&c;
			setcolor(15);
		       //show(i,j,c);
			outtextxy(i,j,ptr);
			b[row][col]=*ptr;
		}
	}
	else if(a==8)
	{	//if(b[row][col]>0)
		//{
			flag=1;
		       /*	setfillstyle(SOLID_FILL,0);
			fillellipse(i+2,j+2,8,8);
			b[row][col]=0;
			k=15;*/
			set_zero(i-4,i+10,j-4,j+10,0);
			k=15;
			//gotoxy(
			/*setcolor(0);
			outtextxy(i,j,b[row][col]);
			textcolor(0);
			cscanf("%c",ptr);
			setcolor(15);
			//gotoxy(
			outtextxy(i,j,ptr);
		       //	scanf("%d",&a);
			b[row][col]=*ptr;
			*/
	}
}
//else if(a>=0 && a<=9) {int k=a; outtextxy(i,j,k);}

return 0;
}