#include <stdio.h> #include <stdlib.h> void helloworld(int e){ FILE *fp1; fp1=fopen("output.txt","w"); int s,point; for(s=1;s<=e;s++){ fprintf(fp1,"Hello World"); //fprintf主要目的是供你將資料,以格式化方式寫入某檔案內 /*fprintf( )和printf( )兩者唯一的差別是, printf( )會將資料列印在螢幕上,而fprintf( )會將資料列印在某個檔案內。*/ for(point=1;point<=s;point++){ fprintf(fp1,"!"); } fprintf(fp1,"\n"); } for(s=e-1;s>0;s--){ fprintf(fp1,"Hello World"); for(point=1;point<=s;point++){ fprintf(fp1,"!"); } fprintf(fp1,"\n"); } fclose(fp1); } int main(int argc, char** argv) { // int number; if(argc > 1) number = (int)atoi(argv[1]); else number = 50; helloworld(number); return 0; }php 取得值並呼叫c執行檔
<?php /************************************************** File:phpCallexe.php Name:執行exe Explain:呼叫C語言並執行 ****************************************By QQBoxy*/ if(isset($_GET['n'])) $num = $_GET['n']; else $num = 20; $cmd = exec('c1.exe '.$num); execInBackground($cmd); echo 'It OK!!'; //------------------------------------------------------- function execInBackground($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ".$cmd."", "r")); } else { exec($cmd." ".$num." > /dev/null &"); } } //------------------------------------------------------- ?>
import java.applet.Applet; import java.awt.*; // for Frame Exit import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class HelloWorldApp extends Applet { Stroke drawingStroke = new BasicStroke(2); public void init() { } public void paint(Graphics g) { int i,p; String peakNumber = ""; peakNumber = getParameter("peakNumber"); if(peakNumber != null) { // 轉成整數使用 Integer.parseInt() // 轉為浮點數使用 Float.parseFloat() p = Integer.parseInt(peakNumber); } else { // 若 peakNumber 取不到值, 則內定為 5 p = 10; } Graphics2D graph = (Graphics2D)g; graph.setStroke(drawingStroke); graph.setPaint(Color.black); for(i=1;i<=p;i++) { graph.drawString("Hello World", 10, 10+i*20); printC(graph,i, 80, 10+i*20); } for(i=p-1;i>=1;i--) { //graph.drawString("Hello World", 10, 10+(10+10-i)*20); //printC(graph,i, 80, 10+(10+10-i)*20); graph.drawString("Hello World", 10, 20+10+(2*p-1)*20-20*i); printC(graph,i, 80, 20+10+(2*p-1)*20-20*i); } } public void stop() { } public void printC(Graphics g, int m, int x, int y){ Graphics2D graph = (Graphics2D)g; int i; for(i=0;i<m;i++) { graph.drawString("!", x+i*10, y); } } public static void main(String[] args) { Frame frm = new Frame("我的主方法(函式)框架"); Applet applet = new HelloWorldApp(); frm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frm.setSize(100, 100); frm.setVisible(true); // 將 applet 加入 Frame 中 frm.add(applet); frm.setSize(300, 300); frm.setVisible(true); applet.init(); } // 結束 main /* Command Lines int i = 0; for(i=1;i<=10;i++) { System.out.print("Hello World"); printC(i); System.out.print("\n"); } for(i=9;i>=1;i--) { System.out.print("Hello World"); printC(i); System.out.print("\n"); } } static void printC(int m){ int i; for(i=0;i<m;i++) { System.out.print("!"); } } */ } // 結束 HelloWorldApp class
java applet由php 取值給入
<applet code="HelloWorldApp" height="500" width="500"> <param name="peakNumber" value="10" /> </applet>
import java.applet.Applet; import java.awt.*; public class HelloWorldApp extends Applet { Stroke drawingStroke = new BasicStroke(2); // static 變數才可以在各方法中共用 String peakNumber = ""; int number; public void init() { peakNumber = getParameter("peakNumber"); if(peakNumber != null) { // 轉成整數使用 Integer.parseInt() // 轉為浮點數使用 Float.parseFloat() number = Integer.parseInt(peakNumber); } else { // 若 peakNumber 取不到值, 則內定為 5 number = 5; } } public void paint(Graphics g) { int i; Graphics2D graph = (Graphics2D)g; graph.setStroke(drawingStroke); graph.setPaint(Color.black); for(i=1;i<=number;i++) { // 每一行向下增量 20 單位 graph.drawString("Hello World", 10, 10+i*20); printC(graph,i, 80, 10+i*20); } for(i=number-1;i>=1;i--) { // 必須考慮前半部已經增量 number*20 graph.drawString("Hello World", 10, 10+(number+number-i)*20); printC(graph,i, 80, 10+(number+number-i)*20); } } public void printC(Graphics g, int m, int x, int y){ Graphics2D graph = (Graphics2D)g; int i; for(i=0;i<m;i++) { graph.drawString("!", x+i*10, y); } s(graph,20,20,15); } public void s(Graphics g, int x, int y, int s){ Graphics2D graph = (Graphics2D)g; graph.drawLine(x, y, x+s, y); graph.drawLine(x+s, y, x+s, y+s); graph.drawLine(x+s, y+s, x, y+s); graph.drawLine(x, y+s, x, y); } public void square(Graphics g, int x, int y, int s){ Graphics2D graph = (Graphics2D)g; graph.drawLine(x, y, x+s, y+s); } }
沒有留言:
張貼留言