struct entry:手动命令行访问?

时间:2015-09-16 19:19:13

标签: objective-c command-line argv argc

这段代码是如何工作的:更准确地说是将结构传递到命令行agc和argv的行?它在做什么?还有另一种方法吗?

#include <Foundation/Foundation.h>

      int main (int argc, char * argv[]) {

        struct entry dictionary[100] =
{   { "aardvark", "a burrowing African mammal"  } ,
    { "abyss", "a bottomless pit' } ,  
    { "acumen", "mentally sharp; keen"
    { "addle",  "to become confused" } , 
    { "aerie", "a high nest" }, 
    { "affix","to append, attach" },
    { "agar"," a jelly made from seaweed" }, 
    { "ahoy"," a nautical call of greeting"  }, 
    { "aigrette", "an ornamental cluster of feathers" } , 
    { "ajar", "partially opened" }        } ;

      int entries = 10;
       int entryNumber;
      int lookup (struct entry dictionary [], char search[],
      int entries); 

if ( argc != 2 ) {
    NSLog (@"No word typed on the command line.");
        return (1); }
   entryNumber = lookup (dictionary, argv[1], entries);
     if ( entryNumber != -1 )
     NSLog (@"%s", dictionary[entryNumber].definition);
     else
   NSLog (@"Sorry, %s is not in my dictionary.", argv[1]);
       return (0); }

0 个答案:

没有答案