C++ strcpy()和strcat()在Turbo C++;(从字符串literal初始化数组时)

C++ strcpy()和strcat()在Turbo C++;(从字符串literal初始化数组时),c++,turbo-c++,C++,Turbo C++,strcpy()和strcat()函数在以下情况下无法正常工作: 在Turbo C++中的我。我在下面给出了我的代码。我希望输出为 是: C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pd.txt C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pr.txt C:\TURBOC3\BIN\BANK\SHOP\CART\311itm.txt C:\TURBOC3\BIN\BANK\SHOP\CART\311pzr.txt 但我得到的结果是: C:\T

strcpy()和strcat()函数在以下情况下无法正常工作: 在Turbo C++中的我。我在下面给出了我的代码。我希望输出为 是:

C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pd.txt
C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pr.txt
C:\TURBOC3\BIN\BANK\SHOP\CART\311itm.txt
C:\TURBOC3\BIN\BANK\SHOP\CART\311pzr.txt
但我得到的结果是:

C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pd.txt
C:\TURBOC3\BIN\BANK\SHOP\SELLER\334pr.txt
C:\TURBOC3\BIN\BANK\SHOP\CART\311itm.txt
4pd.txt
谁能指出我代码中的错误以及如何解决它

void add_to_cart(int se_id,int c_id,char p_name[])
{
    char id_seller[100],id_customer[100],id_seller1[100],id_customer1[100];
    itoa(se_id,id_seller,10);
    itoa(se_id,id_seller1,10);
    itoa(c_id,id_customer,10);
    itoa(c_id,id_customer1,10);
    strcat(id_seller,"pd.txt");
    strcat(id_seller1,"pr.txt");
    strcat(id_customer,"itm.txt");
    strcat(id_customer1,"pzr.txt");
    char location_of_cart_product[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\CART\\",location_of_cart_price[100];
    char location_of_product[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\SELLER\\",lop[100];
    strcpy(location_of_cart_price,location_of_cart_product);
    strcpy(lop,location_of_product);
    strcat(location_of_cart_product,id_customer);
    strcat(location_of_cart_price,id_customer1);
    strcat(lop,id_seller1);
    strcat(location_of_product,id_seller);
    puts(location_of_product);
    puts(lop);
    puts(location_of_cart_product);
    puts(location_of_cart_price);
}
这些声明:

char location_of_cart_product[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\CART\\"
char location_of_product[100]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\SELLER\\"
分配一个大小为33的数组。如果不破坏堆栈,则无法使用strcat附加到此数组。看

你可以写:

char location_of_cart_product[100]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\CART\\";
char location_of_product[100]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\SELLER\\";

它将分配100个字符并用字符串初始化数组的第一部分。< /P>任何人都可以告诉我代码中的错误,甚至Turbo C++有一个调试器,允许您每次在一步查看变量时一行一行。我记得我在20世纪90年代用了几千个小时。你有没有试过在内置调试器中逐行检查你的代码?你如何调用你展示的这个函数?用什么论据?请尝试创建一个标题来展示给我们。请避免将整篇文章当作标题来大写。这真让人分心。请注意合并您的重复帐户。非常感谢您,先生。成功了,非常感谢