2
私はstrtokの機能を模倣しようとしていましたが、セグメント化エラーが発生しました。ここで私を助けてください。ここでこのコードで何が問題になっていますか?
は私のコードです:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char argv[])
{
int i=0;
char c[]="get the hell out of here";
char *p;
char *temp=(char *)malloc(100);
while(c[i]!='\0')
{
if(c[i]!=' ')
{
*temp=c[i];
temp++;
i++;
}
else
{
*temp='\0';
printf("printing tokenn");
puts(temp);
i++;
temp="";
}
}
return 0;
}
* void main * !!!! – dreamlax
@dreamlax void mainは実際に大丈夫ですが、Shashankは '#include'をコードに移動して適切にフォーマットできますか?そして、 'temp =" ";'行の意味は? – Vyktor
@Vyktor: 'void main'は実際には動作するかもしれませんが、合法ではありません。 – jamesdlin