史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   軟體應用問題討論區 (http://forum.slime.com.tw/f5.html)
-   -   C語言中字串的合併 (左右加入") (http://forum.slime.com.tw/thread27669.html)

alex001 2003-04-09 10:57 PM

C語言中字串的合併 (左右加入")
 
各位大家好!
在C語言中有一個傳入參數的寫法,因為我想在傳入的值,加上左" 及右"
我的C語言還不夠好,所以總是有錯誤,能請各位指點一下嗎?謝謝..
下面是我的程式,請各位看一下.(註解的地方是我想加入,但有問題的地方)
比方Compiler後檔名為test.exe,在Dos下執行
C:>test 0001
會輸出成 C:>BARCODE 40,150,\"39\",40,0,0,2,4,"0001

#define string1 "DIRECTION 1"
#define string2 "DENSITY 12"
#define string3 "SPEED 3.0"
#define string4 "REFERENCE 0,0"
#define string5 "SIZE 32 mm,25 mm"
#define string6 "GAP 3 mm,0"
#define string7 "CLS"
#define string8 "TEXT 30,10,\"5\",0,1,1,\"5678\""
#define string9 "TEXT 30,80,\"5\",0,1,1,\"1234\""

#define string11 "PRint 1,1"
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(int argc, char *argv[])
{
char s1[]="BARCODE 40,150,\"39\",40,0,0,2,4,";
/*char s2="/x22";*/
/*strncat(s2,argv[1],20);*/
char string10[80];
void concat();
concat(s1,argv[1],string10);
if(argc != 2)
{
printf("Incorrect Format!!\n");
printf("print try again!!\n");
exit(1);
}
{
fprintf(stdprn,"%s \n",string1);
fprintf(stdprn,"%s \n",string2);
fprintf(stdprn,"%s \n",string3);
fprintf(stdprn,"%s \n",string4);
fprintf(stdprn,"%s \n",string5);
fprintf(stdprn,"%s \n",string6);
fprintf(stdprn,"%s \n",string7);
fprintf(stdprn,"%s \n",string8);
fprintf(stdprn,"%s \n",string9);
fprintf(stdprn,"%s \n",string10);
fprintf(stdprn,"%s ",string11);
}
}
void concat(char str1[],char str2[],char str3[])
{
int i,j,k;
for(i=0;str1[i]!=\0;i++)
str3[i]=str1[i];
for(j=0;str2[j]!=\0;j++)
str3[i+j]=str2[j];
str3[i+j]=\0;
}


所有時間均為台北時間。現在的時間是 11:41 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1