命令列引數
C語言部份:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
printf("testing now\n");
if(argc!=3){
printf("successful part1\n");
}
printf("%s",argv[0]);
return 0;
}
CMD部分:
PS:利用cmd開啟exe檔 並在其後輸入argc的值,可引入函數
重導
https://www.youtube.com/watch?v=xQXAnI9-Z2I&list=PLFI-nbR0eXR5x192m3XVGJzfJxbEcRo2Z&index=9
2017年4月19日 星期三
2017年4月10日 星期一
C&sql
使用C寫入資料庫
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int account;
char name[30];
double balance;
FILE *cfptr;
if((cfptr=fopen("clients2.dat","w"))==NULL){
printf("file could not be opened\n");
}
else{
printf("enter the account ,name,and balance.\n");
printf("enter EOF to end inpute.\n");
printf("?");
scanf("%d%s%.2f",&account,name,&balance);
while(!feof(stdin)){
fprintf(cfptr,"%d %s %.2f\n",account,name,balance);
printf("?");
scanf("%d%s%lf",&account,name,&balance);
}
fclose(cfptr);
}
return 0;
}
PS1:寫入同檔案夾中的資料庫,名字取決於此處clients2:if((cfptr=fopen("clients2.dat","w"))==NULL){
PS2:fopen(檔案名稱, 模式) 以指定模式開啟檔案 其中"W"代表寫入
*************************
使用C讀入資料庫
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int account;
char name[30];
double balance;
FILE *cfptr;
if((cfptr=fopen("clients.dat","r"))==NULL){
printf("could not open\n");
}
else {
printf("%-10s%-13s%s\n","account","name","balance");
fscanf(cfptr,"%d%s%lf",&account,name,&balance);
while(!feof(cfptr)){
printf("%-10d%-13s%7.2f\n",account,name,balance);
fscanf(cfptr,"%d%s%lf",&account,name,&balance);
}
fclose(cfptr);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int account;
char name[30];
double balance;
FILE *cfptr;
if((cfptr=fopen("clients2.dat","w"))==NULL){
printf("file could not be opened\n");
}
else{
printf("enter the account ,name,and balance.\n");
printf("enter EOF to end inpute.\n");
printf("?");
scanf("%d%s%.2f",&account,name,&balance);
while(!feof(stdin)){
fprintf(cfptr,"%d %s %.2f\n",account,name,balance);
printf("?");
scanf("%d%s%lf",&account,name,&balance);
}
fclose(cfptr);
}
return 0;
}
PS1:寫入同檔案夾中的資料庫,名字取決於此處clients2:if((cfptr=fopen("clients2.dat","w"))==NULL){
PS2:fopen(檔案名稱, 模式) 以指定模式開啟檔案 其中"W"代表寫入
*************************
使用C讀入資料庫
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int account;
char name[30];
double balance;
FILE *cfptr;
if((cfptr=fopen("clients.dat","r"))==NULL){
printf("could not open\n");
}
else {
printf("%-10s%-13s%s\n","account","name","balance");
fscanf(cfptr,"%d%s%lf",&account,name,&balance);
while(!feof(cfptr)){
printf("%-10d%-13s%7.2f\n",account,name,balance);
fscanf(cfptr,"%d%s%lf",&account,name,&balance);
}
fclose(cfptr);
}
return 0;
}
訂閱:
意見 (Atom)