各好版友好,本人一直以來都在研究python,而現在公司要我研究一個用C來寫的東西,有些無法take direction
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>#define GET_COUNTER() {
if ((p = strtok(NULL, " \t")) == NULL)
continue;
counter = atoll(p);
}int main()
{
printf("ddd");
}
上面的程式run完後出現以下error:
test.c:8:17: error: expected identifier or '(' before 'if'
8 | if ((p = strtok(NULL, " \t")) == NULL)
| ^~
test.c:10:9: warning: data definition has no type or storage class
10 | counter = atoll(p);
| ^~~~~~~
test.c:10:9: warning: type defaults to 'int' in declaration of 'counter' [-Wimplicit-int]
test.c:10:25: error: 'p' undeclared here (not in a function)
10 | counter = atoll(p);
| ^
test.c:11:1: error: expected identifier or '(' before '}' token
11 | }
| ^
[Finished in 235ms]
請問有沒有熱心的版友知道如何將這段小程式修改至可以運行? 謝謝
如何將這段小程式修改至可以運行?
改好了
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/*
#define GET_COUNTER() {
if ((p = strtok(NULL, " \t")) == NULL)
continue;
counter = atoll(p);
}
*/
int main() {
printf("ddd");
return 0;
}
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define GET_COUNTER() { \
if ((p = strtok(NULL, " \t")) == NULL) \
continue; \
counter = atoll(p); \
}
int main()
{
printf("ddd");
}