小程序am
① 小程序里頁面後退怎麼刷新頁面
一般想實現後退刷新效果,比如判斷是否登錄啊, 這個時候可以在 onShow 函數裡面寫判斷是否登錄,如果沒有登錄跳轉到登錄頁。
再比如判斷頁面是否有載入某個數據, 就在onShow裡面判斷:如果等於空的話, 就再載入一次。
示例代碼:
App({
onLaunch:function(options){
//生命周期函數--監聽小程序初始化當小程序初始化完成時,會觸發onLaunch(全局只觸發一次)
},
onShow:function(options){
//生命周期函數--監聽小程序顯示(後退到這個頁面的時候這個就會被回調)當小程序啟動,或從後台進入前台顯示,會觸發onShow
},
onHide:function(){
//生命周期函數--監聽小程序隱藏當小程序從前台進入後台,會觸發onHide
},
onError:function(msg){
//錯誤監聽函數當小程序發生腳本錯誤,或者api調用失敗時,會觸發onError並帶上錯誤信息
},
globalData:'Iamglobaldata'})
更詳細的資料應該參照官網API看, 因為隨著升級有些方法可能不再適用!
小程序API 網頁鏈接
② 一個ASP小程序
//VBScript的語法我不太懂,你看著改一下吧, JS的語法比較清晰易懂.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
<script language=javaScript>
<!--
function showTime(){
var digital = new Date();
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var day = digital.getDate();
var month = digital.getMonth() + 1;
var year = digital.getYear();
var amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
//if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
dispTime = hours + ":" + minutes + ":" + seconds + " ";// + amOrPm;
var enabled = 0; today = new Date();
var day; var date;
if(today.getDay()==0) day = " 星期日"
if(today.getDay()==1) day = " 星期一"
if(today.getDay()==2) day = " 星期二"
if(today.getDay()==3) day = " 星期三"
if(today.getDay()==4) day = " 星期四"
if(today.getDay()==5) day = " 星期五"
if(today.getDay()==6) day = " 星期六"
document.fgColor = "000000";
var str = ['上午好','下午好','晚上好','夜裡好'];
var i = 0;
if(hours>=0 && hours<=6)
i = 3;
else if(hours>6 && hours<=12)
i = 0;
else if(hours>=12 && hours<=18)
i = 1;
else
i = 2;
date = "今天是:" + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日" + day +" ";
document.getElementById("timeSpan").innerHTML = date + dispTime + str[i];
setTimeout("showTime()", 1000);
}
// -->
</script>
</head>
<body onload="showTime()">
<span id="timeSpan"></span>
</body>
</html>
③ 幫忙寫C++三個小程序
#include <iostream>
using namespace std;
bool ch_24to12(int n)
{
int hour = n/100;
int min = n%100;
if(hour<0 || hour>23) return false;
if(min>59) return false;
if(hour<10) cout<<"0";
cout<<hour;
if(min<10) cout<<"0";
cout<<min;
bool big = false;
if(hour>12)
{
hour -=12;
big = true;
}
else if(hour==12) big = true;
cout<<" is "<<hour<<".";
if(min<10) cout<<"0";
cout<<min;
if(big) cout<<" pm."<<endl;
else cout<<" am."<<endl;
return true;
}
int main(int argc, char *argv[])
{
int n;
cout<<"input a number:";
cin>>n;
if(!ch_24to12(n)) cout<<"Wrong time!"<<endl;
return 0;
}
④ 小程序,找個錯.謝謝
改成這樣,編譯器就不警告了。
#include<stdio.h>
int main()
{
char a[5][10];
char (*p)[10];
for(p=a;p<a+5;p++)
gets(*p);
for(p=a;p<a+5;p++)
puts(*p);
}
char **p,意為p是個指針,它將指向一另一個char指針,該指針指向一個char變數。而不是指向一個char數組。
我也不知道,《The C Puzzle Book》第113頁說:一個數組的地址和這個數組中的第一個元素的地址是有區別的:這兩種地址的類型是不同的,這種區別主要體現在對地址進行算術運算時的遞增量/遞減量方面.
比如int a[3][3],a的類型是指向三元數組的指針,a的基類型是三元int數組,而a+1將指向下一個三元int數組。a[0]的類型是指向int整數的指針,a[0]的基類型是int,而a[0]+1將指向內存中的下一個int整數。
這也許能解釋為什麼編譯器會對p=a給出警告,而非錯誤。不過將p聲明成char (*p)[10]更好。
/*****************************************/
上面的解釋不完全正確,這里有個和你問的是一樣的問題,它由Sun Miscosystems公司的Peter van der Linden先生在其大作《Expert C Programming》中作為第二章例子給出了詳細的解釋。
Reading the ANSI C Standard for Fun, Pleasure, and Profit
Sometimes it takes considerable concentration to read the ANSI C Standard and obtain an answer
from it. A sales engineer sent the following piece of code into the compiler group at Sun as a test case.
1 foo(const char **p) { }
2
3 main(int argc, char **argv)
4{
5 foo(argv);
6}
If you try compiling it, you'll notice that the compiler issues a warning message, saying:
line 5: warning: argument is incompatible with prototype
The submitter of the code wanted to know why the warning message was generated, and what part of
the ANSI C Standard mandated this. After all, he reasoned,
argument char *s matches parameter const char *p
This is seen throughout all library string functions.
So doesn't argument char **argv match parameter const char **p ?
The answer is no, it does not. It took a little while to answer this question, and it's ecational in more
than one sense, to see the process of obtaining the answer. The analysis was carried out by one of
Sun's "language lawyers," [6] and it runs like this:
[6] The New Hacker's Dictionary defines a language lawyer as "a person who will show you the five
sentences scattered through a 200-plus-page manual that together imply the answer to your question 'if only
you had thought to look there.'" Yep! That's exactly what happened in this case.
The Constraints portion of Section 6.3.2.2 of the ANSI C Standard includes the phrase:
Each argument shall have a type such that its value may be assigned to an object with the unqualified
version of the type of its corresponding parameter.
This says that argument passing is supposed to behave like assignment.
Thus, a diagnostic message must be proced unless an object of type const char ** may be
assigned a value of type char **.To find out whether this assignment is legal, flip to the section
on simple assignment, Section 6.3.16.1, which includes the following constraint:
One of the following shall hold:…
• Both operands are pointers to qualified or unqualified versions of compatible types, and the
type pointed to by the left has all the qualifiers of the type pointed to by the right.
It is this condition that makes a call with a char * argument corresponding to a const char *
parameter legal (as seen throughout the string routines in the C library). This is legal because in the
code
char * cp;
const char *ccp;
ccp = cp;
• The left operand is a pointer to "char qualified by const".
• The right operand is a pointer to "char" unqualified.
• The type char is a compatible type with char, and the type pointed to by the left operand
has all the qualifiers of the type pointed to by the right operand (none), plus one of its own
(const).
Note that the assignment cannot be made the other way around. Try it if you don't believe me.
cp = ccp; /* results in a compilation warning */
Does Section 6.3.16.1 also make a call with a char ** argument corresponding to a const
char ** parameter legal? It does not.
The Examples portion of Section 6.1.2.5 states:
The type designated "const float *" is not a qualified type—its type is "pointer to const-qualified float"
and is a pointer to a qualified type.
Analogously, const char ** denotes a pointer to an unqualified type. Its type is a pointer to a
pointer to a qualified type.
Since the types char ** and const char ** are both pointers to unqualified types that are
not the same type, they are not compatible types. Therefore, a call with an argument of type char
** corresponding to a parameter of type const char ** is not allowed. Therefore, the
constraint given in Section 6.3.2.2 is violated, and a diagnostic message must be proced.
This is a subtle point to grasp. Another way of looking at it is to note that:
• the left operand has type FOO2—a pointer to FOO, where FOO is an unqualified pointer to a
character qualified by the const qualifier, and
• the right operand has type BAZ2—a pointer to BAZ, where BAZ is an unqualified pointer to
a character with no qualifiers.
FOO and BAZ are compatible types, but FOO2 and BAZ2 differ other than in qualifica-tion of the
thing immediately pointed to and are therefore not compatible types; therefore the left and right
operands are unqualified pointers to types that are not compatible. Compatibility of pointer types is
not transitive. Therefore, the assignment or function call is not permitted. However, note that the
restriction serves mainly to annoy and confuse users. The assignment is currently allowed in C++
translators based on cfront (though that might change).
Handy Heuristic
Const Isn't
The keyword const doesn't turn a variable into a constant! A symbol with the const
qualifier merely means that the symbol cannot be used for assignment. This makes the value
re ad -onl y through that symbol; it does not prevent the value from being modified through
some other means internal (or even external) to the program. It is pretty much useful only
for qualifying a pointer parameter, to indicate that this function will not change the data that
argument points to, but other functions may. This is perhaps the most common use of
const in C and C++.
A const can be used for data, like so:
const int limit = 10;
and it acts somewhat as in other languages. When you add pointers into the equation, things
get a little rough:
const int * limitp = &limit;
int i=27;
limitp = &i;
This says that limitp is a pointer to a constant integer. The pointer cannot be used to
change the integer; however, the pointer itself can be given a different value at any time. It
will then point to a different location and dereferencing it will yield a different value!
The combination of const and * is usually only used to simulate call-by-value for array
parameters. It says, "I am giving you a pointer to this thing, but you may not change it."
This idiom is similar to the most frequent use of void *. Although that could
theoretically be used in any number of circumstances, it's usually restricted to converting
pointers from one type to another.
Analogously, you can take the address of a constant variable, and, well, perhaps I had better
not put ideas into people's heads. As Ken Thompson pointed out, "The const keyword
only confuses library interfaces with the hope of catching some rare errors." In retrospect,
the const keyword would have been better named readonly.
True, this whole area in the standard appears to have been rendered into English from Ur via Danish
by translators who had only a passing familiarity with any of these tongues, but the standards
committee was having such a good time that it seemed a pity to ruin their fun by asking for some
simpler, clearer rules.
We felt that a lot of people would have questions in the future, and not all of them would want to
follow the process of reasoning shown above. So we changed the Sun ANSI C compiler to print out
more information about what it found incompatible. The full message now says:
Line 6: warning: argument #1 is incompatible with prototype:
prototype: pointer to pointer to const char : "barf.c", line
1
argument : pointer to pointer to char
Even if a programmer doesn't understand why, he or she will now know what is incompatible
⑤ 如何通過編碼實現控制系統時間的AM PM文字內容
控制面板-區域和語言選項-區域選項-自定義-時間-時間格式
在下拉菜單里選擇tt h:mm:ss或tt hh:mm:ss即可!
⑥ 求高手給一個C語言簡單實用小程序
簡易計算器程序。
#include <dos.h> /*DOS介面函數*/
#include <math.h> /*數學函數的定義*/
#include <conio.h> /*屏幕操作函數*/
#include <stdio.h> /*I/O函數*/
#include <stdlib.h> /*庫函數*/
#include <stdarg.h> /*變數長度參數表*/
#include <graphics.h> /*圖形函數*/
#include <string.h> /*字元串函數*/
#include <ctype.h> /*字元操作函數*/
#define UP 0x48 /*游標上移鍵*/
#define DOWN 0x50 /*游標下移鍵*/
#define LEFT 0x4b /*游標左移鍵*/
#define RIGHT 0x4d /*游標右移鍵*/
#define ENTER 0x0d /*回車鍵*/
void *rar; /*全局變數,保存游標圖象*/
struct palettetype palette; /*使用調色板信息*/
int GraphDriver; /* 圖形設備驅動*/
int GraphMode; /* 圖形模式值*/
int ErrorCode; /* 錯誤代碼*/
int MaxColors; /* 可用顏色的最大數值*/
int MaxX, MaxY; /* 屏幕的最大解析度*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*畫邊框函數*/
void initialize(void); /*初始化函數*/
void computer(void); /*計算器計算函數*/
void changetextstyle(int font, int direction, int charsize); /*改變文本樣式函數*/
void mwindow(char *header); /*窗口函數*/
int specialkey(void) ; /*獲取特殊鍵函數*/
int arrow(); /*設置箭頭游標函數*/
/*主函數*/
int main()
{
initialize();/* 設置系統進入圖形模式 */
computer(); /*運行計算器 */
closegraph();/*系統關閉圖形模式返迴文本模式*/
return(0); /*結束程序*/
}
/* 設置系統進入圖形模式 */
void initialize(void)
{
int xasp, yasp; /* 用於讀x和y方向縱橫比*/
GraphDriver = DETECT; /* 自動檢測顯示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化圖形系統*/
ErrorCode = graphresult(); /*讀初始化結果*/
if( ErrorCode != grOk ) /*如果初始化時出現錯誤*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*顯示錯誤代碼*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 讀面板信息*/
MaxColors = getmaxcolor() + 1; /* 讀取顏色的最大值*/
MaxX = getmaxx(); /* 讀屏幕尺寸 */
MaxY = getmaxy(); /* 讀屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷貝縱橫比到變數中*/
AspectRatio = (double)xasp/(double)yasp;/* 計算縱橫比值*/
}
/*計算器函數*/
void computer(void)
{
struct viewporttype vp; /*定義視口類型變數*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作數和計算結果變數*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定義字元串在按鈕圖形上顯示的符號 */
mwindow( "Calculator" ); /* 顯示主窗口 */
color = 7; /*設置灰顏色值*/
getviewsettings( &vp ); /* 讀取當前窗口的大小*/
width=(vp.right+1)/10; /* 設置按鈕寬度 */
height=(vp.bottom-10)/10 ; /*設置按鈕高度 */
x = width /2; /*設置x的坐標值*/
y = height/2; /*設置y的坐標值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*畫一個二維矩形條顯示運算數和結果*/
setcolor( color+3 ); /*設置淡綠顏色邊框線*/
rectangle( x+width*2, y, x+7*width, y+height );
/*畫一個矩形邊框線*/
setcolor(RED); /*設置顏色為紅色*/
outtextxy(x+3*width,y+height/2,"0."); /*輸出字元串"0."*/
x =2*width-width/2; /*設置x的坐標值*/
y =2*height+height/2; /*設置y的坐標值*/
for( j=0 ; j<4 ; ++j ) /*畫按鈕*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*畫一個矩形條*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*將字元保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移動列坐標*/
}
y +=(height/2)*3; /* 移動行坐標*/
x =2*width-width/2; /*復位列坐標*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移動游標到x,y位置*/
arrow(); /*顯示游標*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*設置str2為空串*/
while((v=specialkey())!=45) /*當壓下Alt+x鍵結束程序,否則執行下面的循環*/
{
while((v=specialkey())!=ENTER) /*當壓下鍵不是回車時*/
{
putimage(x,y,rar,XOR_PUT); /*顯示游標圖象*/
if(v==RIGHT) /*右移箭頭時新位置計算*/
if(x>=x0+6*width)
/*如果右移,移到尾,則移動到最左邊字元位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
m++;
} /*否則,右移到下一個字元位置*/
if(v==LEFT) /*左移箭頭時新位置計算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到頭,再左移,則移動到最右邊字元位置*/
else
{
x=x-width-width/2;
m--;
} /*否則,左移到前一個字元位置*/
if(v==UP) /*上移箭頭時新位置計算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到頭,再上移,則移動到最下邊字元位置*/
else
{
y=y-height-height/2;
n--;
} /*否則,移到上邊一個字元位置*/
if(v==DOWN) /*下移箭頭時新位置計算*/
if(y>=7*height)
{
y=y0;
n=0;
} /*如果移到尾,再下移,則移動到最上邊字元位置*/
else
{
y=y+height+height/2;
n++;
} /*否則,移到下邊一個字元位置*/
putimage(x,y,rar,XOR_PUT); /*在新的位置顯示游標箭頭*/
}
c=str1[n*5+m]; /*將字元保存到變數c中*/
if(isdigit(c)||c=='.') /*判斷是否是數字或小數點*/
{
if(flag==-1) /*如果標志為-1,表明為負數*/
{
strcpy(str2,"-"); /*將負號連接到字元串中*/
flag=1;
} /*將標志值恢復為1*/
sprintf(temp,"%c",c); /*將字元保存到字元串變數temp中*/
strcat(str2,temp); /*將temp中的字元串連接到str2中*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2); /*顯示字元串*/
}
if(c=='+')
{
num1=atof(str2); /*將第一個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=1; /*做計算加法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2為空,說明是負號,而不是減號*/
flag=-1; /*設置負數標志*/
else
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=2; /*做計算減法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
}
if(c=='*')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=3; /*做計算乘法標志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='/')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=4; /*做計算除法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='^')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=5; /*做計算乘方標志值*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='%')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=6; /*做計算模運算乘方標志值*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='=')
{
num2=atof(str2); /*將第二個操作數轉換為浮點數*/
switch(act) /*根據運算符號計算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做減法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模運算*/
}
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結果區*/
sprintf(temp,"%f",result); /*將結果保存到temp中*/
outtextxy(5*width,height,temp); /*顯示結果*/
}
if(c=='c')
{
num1=0; /*將兩個操作數復位0,符號標志為1*/
num2=0;
flag=1;
strcpy(str2,""); /*將str2清空*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結果區*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='Q')exit(0); /*如果選擇了q回車,結束計算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去游標箭頭*/
return; /*返回*/
}
/*窗口函數*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除圖形屏幕 */
setcolor( MaxColors - 1 ); /* 設置當前顏色為白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 設置視口大小 */
height = textheight( "H" ); /* 讀取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*設置文本樣式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*設置字元排列方式*/
outtextxy( MaxX/4, 2, header ); /*輸出標題*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*設置視口大小*/
drawboder(); /*畫邊框*/
}
void drawboder(void) /*畫邊框*/
{
struct viewporttype vp; /*定義視口類型變數*/
setcolor( MaxColors - 1 ); /*設置當前顏色為白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*設置畫線方式*/
getviewsettings( &vp );/*將當前視口信息裝入vp所指的結構中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*畫矩形邊框*/
}
/*設計滑鼠圖形函數*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定義多邊形坐標*/
setfillstyle(SOLID_FILL,2); /*設置填充模式*/
fillpoly(8,raw); /*畫出一游標箭頭*/
size=imagesize(4,4,16,16); /*測試圖象大小*/
rar=malloc(size); /*分配內存區域*/
getimage(4,4,16,16,rar); /*存放游標箭頭圖象*/
putimage(4,4,rar,XOR_PUT); /*消去游標箭頭圖象*/
return 0;
}
/*按鍵函數*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待鍵盤輸入*/
key=bioskey(0); /*鍵盤輸入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊鍵的掃描值,其餘為0*/
return(key); /*返回鍵值*/
}
⑦ C語言小程序!!!
#include<stdio.h>
void main()
{
char str1[30]={"i am a boy"};
char str2[]={"you are a teacher"};
int i,j,k;
i=0,j=0;
while(str1[i]!='\0') {i++;}
while(str2[j]!='\0')
{
str1[i]=str2[j];
i++,j++;
}
for(i=0;i<30;i++)
printf("%c",str1[i]);
}
⑧ 用java 寫一個小程序
String str= new String("I am tomato");
byte[] b = new byte[str.length()];
for(int i=0; i<str.length();i++){
if(str.charAt(i)!=32){
b[i]=(byte)(str.charAt(i)+1);
}else
b[i]=(byte)str.charAt(i);
}
String str2=new String(b);
System.out.println(str2);
⑨ 求一WEB 小程序,JAVASCRIPT寫 在網頁上第一行顯示今天是星期幾 第二行顯示當前時間
隨手寫的,不是很完美,但,復合要求,把這段貼到記事本中,將後綴名改成.html結尾即可運行。
比如aaa.txt ----> aaa.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>日期</title>
<script language="javascript">
function show()
{
var x= new Date();
var y=x.getYear();// 年
var m=x.getMonth();//月
var d=x.getDay();//星期
var ds=x.getDate();//日
var h=x.getHours();//小時
var m1=x.getMinutes();//分
var s=x.getSeconds();//秒
var day;
if (x.getDay()==0) day="星期日";
if (x.getDay()==1) day="星期一";
if (x.getDay()==2) day="星期二";
if (x.getDay()==3) day="星期三";
if (x.getDay()==4) day="星期四";
if (x.getDay()==5) day="星期五";
if (x.getDay()==6) day="星期六";
var timer=""+((h>12) ? h-12 : h);
timer +=((m1<10) ? ":0 " : ":")+m1;
timer +=((s<10) ? ":0 " : ":" )+s;
timer += ""+((h >=12) ? "pm" : "am");
document.s1.b1.value=y;
document.s1.b2.value=m+1;
document.s1.b3.value=ds;
document.s1.b4.value=timer;
document.s1.b5.value=day;
setTimeout("show()",1000);
}
</script>
</head>
<body onload="show()">
<form name="s1" onSubmit="0">
今天<input type="text" name="b5" size="5">
<br><BR>
當前時間:<input type="text" name="b1" size="5">年
<input type="text" name="b2" size="5">月
<input type="text" name="b3" size="5">日
<input type="text" name="b4" size="15">
</form>
</body>
</html>
希望對樓主有用。