idiodandw 2021-05-28 16:48 采纳率: 100%
浏览 35
已采纳

求第三题怎么做!!!!!谢谢各位大佬

 

  • 写回答

2条回答 默认 最新

  • qfl_sdu 2021-05-28 17:54
    关注

    代码如下,如有帮助,请采纳一下,谢谢。

    #include <stdio.h>
    #include <string>
    void main()
    {
    	char** things ; //存储1000个商品
    	int i,j;
    	char buf[12];
    
    	things = new char*[1000];
    	for (i = 0; i < 1000;i++)
    	{
    		*(things+i) = new char[12];
    		sprintf_s(*(things+i),12,"%010d",i+1);
    	}
    
    	for (j = 0; j < 3; j++)
    	{
    		printf("%s\n",*(things+j) );
    	}
    	printf("请输入要查找的编号:");
    	scanf("%s",buf);
    	for (i = 0; i < 1000;i++)
    	{
    		if(strcmp(*(things+i),buf) == 0)
    		{
    			printf("位置:%d",i);
    			break;
    		}
    	}
    	if(i == 1000)
    		printf("找不到相应的产品\n");
    
    	for (i = 0; i < 1000; i++)
    	{
    		delete[] *(things+i);
    	}
    	delete[] things;
    
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?