處理函數的時候好像出了甚麼問替
小的見識淺薄不知道是哪裡出了問題
求大神點解為甚麼會Segmentation fault
下面是我的程式碼
#include<iostream>
#include<string.h>
using namespace std;
int findcar(char assign[],char brand[],char color[])
{
char *sp[10];
char str[10];
bool k=false;
if(assign[0]=='b')
{
*sp=strtok(assign," ");
*sp=strtok(NULL," ");
if(strcmp(*sp,brand)==0)
k=true;
}
else if(assign[0]=='c')
{
*sp=strtok(assign," ");
*sp=strtok(NULL," ");
if(strcmp(*sp,color)==0)
k=true;
}
if(k==true)
return 1;
else
return 0;
}
int main()
{
class A_car{
public:
char brand[10];
char color[10];
};
int n,m,i,j,k;
while(cin>>n>>m)
{
A_car car[n];
char assign [m][30];
/* read the car data*/
for(i=0;i<n;i++)
cin>>car[i].brand>>car[i].color;
/* read the assign data*/
for(i=0;i<=m;i++)
cin.getline(assign[i-1],30);
/* cope with each assignment */
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
k=findcar(assign[i],car[j].brand,car[j].color);
if(k==1)
cout<<car[j].brand<<" "<<car[j].color<<"\n";
}
}
}
return 0;
}