⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demonstrator.c

📁 The collection of AVR source code in C.
💻 C
字号:
// Demonstrator.c Pointer Array Test version

#include "PC_Comm.h"

void initializer()
{
	// Calibrate the oscillator:
    OSCCAL_calibration();   
	// Initialize the USART
	USARTinit();
	
	// say hello
	sendString("\rPointer Array Test.\r\r");   	 

	Test();

}

void parseInput(char s[])
{
	// Do nothing in this test
}
void Test()
{

	// The hard way
	sendChar('H');					
    sendChar('e');
    sendChar('l');
    sendChar('l');
    sendChar('o');
    sendChar(' ');
	sendChar('w');
    sendChar('o');
    sendChar('r');        
 	sendChar('l');
    sendChar('d');
    sendChar('!');        
    sendChar('\r');

	SayHowdy();
	
	Confuseus();
	
	Confuseusmore();

}

void SayHowdy()
{ 
	char greet[] = "Hello, world!\r*";
	
	sendString("\rIn SayHowdy()\r");	

	for(int i =0 ; greet[i] != '*'; i++)
	{
		sendChar(greet[i]);
	}
}

void Confuseus()
{
	char howdy[] = {'h','o','w','d','y','\0'};
	char *confuseus; 		// create a char pointer
	char c; 				// create a char variable;
	char c1, c2;			// and a couple more
	
	sendString("\rIn Confuseus()\r");	
	
	confuseus = &howdy[0]; 	// set confuseus to point to the howdy array;
	confuseus += 4;  		// set it to point to howdy[4]
	c = *confuseus;		// set the contents of c to the contents of howdy[4]
	sendString("c = *confuseus; = ");
	sendChar(c);
	sendChar('\r');
	
	confuseus -= 4; // reset the pointer
	c1 = *(confuseus + 1);
	sendString("c1 = *(confuseus + 1); = ");
	sendChar(c1);
	sendChar('\r');
	
	c2 = *confuseus + 1;
	sendString("c2 = *confuseus + 1; = ");
	sendChar(c2);
	sendChar('\r');

}

void Confuseusmore()
{
	char howdy[] = {'h','o','w','d','y','\0'};
	int i  = 4;
	char c1,c2;
	char* confuseusmore;

	sendString("\rIn Confuseusmore()\r");

	c1 = howdy[i];			// c1 = 'y' using array notation
	sendString("c1 = howdy[i]; = ");
	sendChar(c1);
	sendChar('\r');	
	
	c2 = *(howdy + 4); 		// c2 = 'y' using pointer notation
	sendString("c2 = *(howdy + 4); = ");
	sendChar(c2);
	sendChar('\r');	
	
	confuseusmore = &howdy[i]; 	// confuseusmore points to 'y'
	sendString("confuseusmore = &howdy[i]; = ");
	sendChar(*confuseusmore);
	sendChar('\r');	
	
	confuseusmore = howdy + i - 1; 	// confuseusmore points to 'd'
	sendString("confuseusmore = howdy + i - 1; = ");
	sendChar(*confuseusmore);
	sendChar('\r');	

}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -