賦值中的不兼容類型執行main,它會要求輸入。char *到char [200]
將輸入存儲在argbuf中。
然後,使用strwrd分裂argbuf爲標記
然而,它說: 「錯誤:不兼容的類型中的char分配*爲char [200]」
我想不通爲什麼..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char argbuf[200];//used to store input
char *strwrd(char *s, char *buf, size_t len, char *delim){
s += strcspn(s, delim);
int n = strcspn(s, delim); /* count the span (spn) of bytes in */
if (len-1 < n) /* the complement (c) of *delim */
n = len-1;
memcpy(buf, s, n);
buf[n] = 0;
s += n;
return (*s == 0) ? NULL : s;
}
int main(){
fgets(argbuf, sizeof(argbuf), stdin);
char token[10][20];
int index;
for (index = 0; index < 10; index++) {
argbuf = strwrd(argbuf, token[index], sizeof(token[index]), " \t");
if (argbuf == NULL)
break;
}
return 1;
}
謝謝你提醒我。我總是試着回答問題......但是,我是編程新手...... – mabeiyi
[C中的char *和char \ [\]之間的差異的可能重複(http://stackoverflow.com/questions/10054271/) char-char-in-c) – netcoder
我不知道。我沒有這樣做 – mabeiyi