Передача аргумента 1 делает указатель из целого числа без приведения - PullRequest
2 голосов
/ 17 февраля 2012
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSDictionary * ProbablyInaccurateFinnishtoEnglshtranslation= [NSDictionary dictionaryWithObjectsAndKeys: @"postilaatikko", @"mailbox", @"oppikirja", @"textbook", @"näppäimistö", @"keyboard", @"piano", @"piano", @"laskukone", @"calculator", @"manteli", @"almond", @"lumi", @"snow", @"vuori", @"mountain", @"aika", @"time", @"kynttilä", @"candle", nil];
    NSString * inputSentence;
    char cstring[451];
    NSArray * sentenceIntoWords;
    NSMutableString * translatedSentence;
    int i = 0;

    NSLog(@"Enter a sentence: \n");
    //scanf("%s", &cstring);
    gets (cstring);

    inputSentence = [NSString stringWithCString: cstring encoding: NSASCIIStringEncoding];

    sentenceIntoWords = [inputSentence componentsSeparatedByString: @" "];

    for(i=0; i<[sentenceIntoWords count]; i++)
    {
        if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:[sentenceIntoWords objectAtIndex:i] == nil])
        {
            translatedSentence = [NSMutableString stringWithString: [sentenceIntoWords objectAtIndex: i]];

        }
        else {
            translatedSentence= [ProbablyInaccurateFinnishtoEnglshtranslation objectForKey: [sentenceIntoWords objectAtIndex: i]];
        }
    }


    NSLog(@"%@", translatedSentence);
    [pool drain];
    return 0;
}

Я пытаюсь сравнить каждое слово предложения, введенного пользователем, с NSArray, заменяя ключ переведенным словом при сопоставлении.Хорошо, поэтому я изменил это на следующее: if ([последнее слово входного предложения отображается, есть ли ошибка в моей логике?

Ответы [ 3 ]

2 голосов
/ 17 февраля 2012

Кронштейн не в том месте.Вы хотите это:

if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:[sentenceIntoWords objectAtIndex:i]] == nil)

То, что вы сейчас имеете, примерно эквивалентно этому:

BOOL isNil = [sentenceIntoWords objectAtIndex:i]] == nil;
if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:isNil)

Очевидно, что это неправильно, поскольку objectForKey (наиболее вероятно) ожидает указатель объекта,не логическое значение.

0 голосов
/ 31 мая 2014

Похожая ошибка, которую он показывает в моей программе, iepassing аргумент 1 'strlen' делает указатель из целого числа без приведения

// Программа для чтения последовательности fastta и ее рандомизации!

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

int main(int ac,char *av[])
{
  int i;
  int l1;
  FILE *file1;

  if ( ac < 2 ) return 0;
  file1= fopen( av[1] , "r" );    //"r" is a string and 'r' is a character
  char x;
  while(((x=fgetc(file1))!= EOF) && (x!='\n'));    //skip the header part
  while(((x=fgetc(file1))!= EOF) && (x!='>'))
    {
      if(isalpha(x))                             //reading all the alphabets after this(>) sign

        {
        printf("%c",x);

        }
    }

//To calculate the length of sequence

   l1=strlen(x);
   printf ("The sequence is %d characters long.\n",l1);

  //to Randomize all the characters present in a string(FASTA sequence)
  srand(time(NULL));

  for (i=l1-1;i>0;i--)
   {
    char j = rand() % (i+1);
    char temp = j;  
     j = x;
     x = temp;

   }
  fclose(file1);
  return 0;
}
0 голосов
/ 17 февраля 2012

Вы не можете использовать примитивные типы с objectForKey:.

if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:[sentenceIntoWords objectAtIndex:i] == nil])  

[sentenceIntoWords objectAtIndex:i] == nil строка выдаст вам логический вывод

, так что это неправильно if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:boolean_value(yes/NO))

вы должны сделать так

if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:[sentenceIntoWords objectAtIndex:i]] == nil)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...