C - 如何在我当前所在的令牌之前获得令牌?

C - How do I get the token before the one I'm currently in?

我正在尝试 return 将我当前所在的令牌之前的令牌发送到 C 中的控制台到文件中。令牌由定界符分隔。我需要实施某种计数器吗?

这是我的代码。

#include <stdio.h>
#include <string.h>

int main (int argc, char **argv)
{
    char line [1000];
    char *delimeters = ".,; \t\n";
    FILE *input = fopen (argv[2], "r");

    while(fgets(line,1000,input) != NULL)
    {
        char *word = strtok(line, delimeters);

        while(word != NULL)
        {
            if(word != NULL && strcmp(word,"(") == 0)
            {
                printf("Enters IF 3\n");
                char *method_name = strtok(NULL, delimeters); //NEED BEFORE WORD
                printf ("Method %s\n", method_name);
            }

好吧,我想通了,而不是在 if 语句中寻找之前的标记,我必须在 if 语句中寻找之前的东西。无论如何,这都是一个棘手的问题。

示例:Method Return_type Something ();

而不是寻找 (,我必须寻找 Method,然后用 strtok 跳转到 Something