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

 

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

#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;

}

 

供参考:

#include<stdio.h>
#include<string.h>
int main()
{
    char str[1000][12]={"1234567890","2345678901","3456789012","4567890123"},*p=str[0];
    char s[12]={0};
    int  i;

    scanf("%s",s);

    for(i=0;i<1000;i++){
        if(strcmp(p+i*12,s)==0) break;
    }
    if(i<1000) printf("%d,%s\n",i,p+i*12);// str[i]);
    else       printf("No found\n");
    
    return 0;
}