Arguments in main() ignored when debugging in Visual C++

限于喜欢 提交于 2019-12-14 01:22:42

问题


Up to this point I've been able to correctly view the output of my C codes by using the debugging command in Visual C++. However, when the script relies on parameters in the main function (eg/ argc, argv), the debugger seems to ignore both parameters and treat them as though they are uninitialized.

For instance, in the following code, the output is always printf("Usage: find pattern\n");.

#include <stdio.h>
#include <string.h>
#define MAXLINE 1000

int getline(char *line, int max);

/* find: print lines that match pattern from 1st arg */
main(int argc, char *argv[])
{
    char line[MAXLINE];
    int found = 0;

    if (argc != 2)
        printf("Usage: find pattern\n");
    else
        while (getline(line, MAXLINE) > 0)
            if (strstr(line, argv[1]) != NULL) {
                printf("%s", line);
                found++;
            }
    system("Pause");
    return found;
}

int getline(char *s, int lim)
{
    int c;
    char *i = s;

    while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
        *s++ = c;
    if (c == '\n')
        *s++ = c;
    *s = '\0';
    return s-i;
}

How can I run the code such that argc and argv get used? Should I perhaps be using an IDE other than Visual C++?

来源:https://stackoverflow.com/questions/17257104/arguments-in-main-ignored-when-debugging-in-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!