[問題] argc問題

看板C_and_CPP (C/C++)作者 (傻傻)時間16年前 (2009/10/29 14:22), 編輯推噓2(208)
留言10則, 3人參與, 最新討論串1/1
這是一個用來 copy 一檔案 至 另一檔案程式,我complier後會產生一個Projec.exe 在MS-DOS模式下,鍵入如下指令: Project.exe a.txt b.txt 即可將a的內容複製到b 問題是:是否可以在另一個程式直接呼叫我的Proect.exe就可以產生同樣功能? #include <stdio.h> #include <stdlib.h> void main(int argc, char *argv[]) { char c; int toScreen = 1; FILE *fpin, *fpout; if(argc < 2 || argc > 3) { printf("The correct format is: copyFile file1 file2\n"); exit(1); } fpin = fopen(argv[1], "r"); if( !fpin ) { printf("The file: %s is not found!\n", argv[1]); return; } if(argc == 3) { fpout = fopen(argv[2], "w"); if( !fpout ) { printf("The file: %s is not found, or no available space!\n", argv[2]); return; } toScreen = 0; } while( (c=getc(fpin)) != EOF) { if( toScreen ) putchar(c); else putc(c, fpout); } fclose(fpin); if( !toScreen) fclose(fpout); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.210.112.66

10/29 14:25, , 1F
就是直接用另一個程式呼叫,而不需要在開啟cmd 打那些指令
10/29 14:25, 1F

10/29 14:32, , 2F
system() ?? 把完整或整確的相對路徑與需要的參數給下去
10/29 14:32, 2F

10/29 14:33, , 3F
應該可以吧??
10/29 14:33, 3F

10/29 14:39, , 4F
使用 bat2exe.exe即可
10/29 14:39, 4F

10/29 15:17, , 5F
有比較具體一點的code嗎,剛剛研究一下bat2還是不太清楚@@
10/29 15:17, 5F

10/29 15:19, , 6F
抱歉~可能我說得不太清楚,我是要自己寫一個程式去呼叫
10/29 15:19, 6F

10/29 15:27, , 7F
新程式裡: system("Project.exe a.txt b.txt"); 這樣??
10/29 15:27, 7F

10/29 15:28, , 8F
Project.exe要和新程式放一起, a.txt與b.txt如果不和
10/29 15:28, 8F

10/29 15:28, , 9F
Project.exe在一起, 要指定它們應有的路徑....
10/29 15:28, 9F

10/29 15:52, , 10F
感謝您...已經ok囉
10/29 15:52, 10F
文章代碼(AID): #1AwJI_b0 (C_and_CPP)
文章代碼(AID): #1AwJI_b0 (C_and_CPP)