AD Teaching Wiki
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

FrontPage

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 525 as of 2010-06-10 09:40:02
AD Teaching Wiki:
  • ProgrammierenCplusplusSS2010
  • AktuellesBlattFragen

Fragen und Kommentare zur 7. Vorlesung / zum 7. Übungsblatt

@Martin: Was passiert, wenn Sie in in Ihrem Test schreiben

    int argc = 3;
    char* argv[3];
    argv[0] = const_cast<char*>("");
    argv[1] = const_cast<char*>("--output-file=out.txt");
    argv[2] = const_cast<char*>("P");

Läuft der Test dann durch? Hannah 10Jun10 10:39

Bin gerade dabei die parseCommandLineArguments Funktion mit den Optionen input-file und output-file zu testen. Hock' jetzt schon 'ne Weile dran und find' den Fehler nicht. Vielleicht hat jemand gerade mehr Gehirnschmalz, als ich. Hier das Codestück in der Grep.cpp (Ich hoffe, dass ist OK, wenn ich das hier rein Stelle, ist ja nicht wirklich viel mehr als das von der Vorlesung):

  // First parse the options.
  struct option options[] =
  {
    {"input-file"            , 1, NULL, 'i'},
    {"output-file"           , 1, NULL, 'o'},
    {"case-insensitive-match", 0, NULL, 'c'},
    {NULL                    , 0, NULL,  0 }
  };
  while (true)
  {
    int c = getopt_long(argc, argv, "ioc", options, NULL);
    if (c == -1) break;
    switch (c)
    {
      case 'i':
        _inputFileName = optarg;
        break;
      case 'c':
        _caseSensitiveMatch = false;
        break;
      case 'o':
        _outputFileName = optarg;
        break;
      default:
        printUsage();
        exit(1);
    }

Mein Test:

    Grep grep;
    int argc = 4;
    char* argv[4];
    argv[0] = const_cast<char*>("");
    argv[1] = const_cast<char*>("--output-file");
    argv[2] = const_cast<char*>("out.txt");
    argv[3] = const_cast<char*>("P");
    grep.parseCommandLineArguments(argc, argv);
    ASSERT_EQ(0, grep._inputFileName[0]);
    ASSERT_EQ('P', grep._pattern[0]);
    ASSERT_EQ(0, grep._pattern[1]);
    ASSERT_EQ('o', grep._outputFileName[0]);
    ASSERT_EQ('u', grep._outputFileName[1]);
    ASSERT_EQ('t', grep._outputFileName[2]);
    ASSERT_EQ('.', grep._outputFileName[3]);
    ASSERT_EQ('t', grep._outputFileName[4]);
    ASSERT_EQ('x', grep._outputFileName[5]);
    ASSERT_EQ('t', grep._outputFileName[6]);

Fehlermeldung:

Value of: grep._outputFileName[0]
  Actual: '\0' (0, 0x0)
Expected: 'o'
Which is: 'o' (111, 0x6F)

Den Test für das input file hab' ich im Prinzip analog dazu gemacht. Der funktioniert. MartinS 10Jun10 10:34

@Simson: Indeed, da fehlt ein Punkt, danke für den Hinweis! Habe ihn jetzt gerade noch zugefügt und die neue Version committed. Machen Sie einfach svn update, dann bekommen Sie ihn auch :-) Hannah 10Jun10 00:14

Sollte isMatch("This is just a line", "a..ne$") wirklich wahr zurückgeben? Fehlt da nicht ein . ? Simson 10Jun10 00:09

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01