Not all control paths return a value - path

if(newNode->getData()->name<currNode->getData()->name)
{
if(currNode->getLeftChild()==NULL)
{
return currNode;
}
compare(newNode,currNode->getLeftChild());
}
else if(newNode->getData()->name>=currNode->getData()->name)
{
if(currNode->getRightChild()==NULL)
{
return currNode;
}
compare(newNode,currNode->getRightChild());
}
else
{
currNode==NULL;
return currNode;
}
Does the last else not cover any other paths that could be taken?
Why am i still getting an error saying not all control paths return a value?
What am I missing? and any hints on a better solution would be nice!
Thank you for your time.

Use below code
if(newNode->getData()->name<currNode->getData()->name)
{
if(currNode->getLeftChild()==NULL)
{
return currNode;
}
compare(newNode,currNode->getLeftChild());
return currNode;
}
else if(newNode->getData()->name>=currNode->getData()->name)
{
if(currNode->getRightChild()==NULL)
{
return currNode;
}
compare(newNode,currNode->getRightChild());
return currNode;
}
else
{
currNode==NULL;
return currNode;
}
You are not returning any value in first and second else part
if u dont want to return anything just use return "";

Related

Expected expression before else statement

I get an error saying Expected expression before my else-statement but I do not know why. I searched through other posts but I cant find a solution.
- (void)setDeviationSize:(double)newDeviation
{
if (newDeviation != 0) {
deviationLayer.lineWidth = 2.0 / newDeviation;
if (newDeviation * pixelPerMeter * scrollView.zoomScale < 2 * cPointRadius) {
deviationLayer.hidden = YES;
} else {
deviationLayer.hidden = NO;
deviationLayer.transform = CATransform3DMakeScale(newDeviation, newDeviation, 0);
}
} else {
deviationLayer.hidden = YES;
} else <---- EXPECTED EXPRESSION {
for(LectureModel* lecture in lectures) {
NSString *title;
if([lecture.title length] > 30) {
title = [NSString stringWithFormat:#"%#...", [lecture.title substringToIndex:30]];
} else {
title = lecture.title;
}
[alert addActionWithTitle:title handler:^(UIAlertAction * _Nonnull action) {
LectureModel* full = [LectureModel findById:lecture.id];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self showModelInPopover:full];
} else {
[[TransitionManager shared] openModelInCatalog:full];
}
}
[self presentViewController:alert animated:YES completion:nil];
}
}
}
What am I missing?
Like vadian and luk2302 pointed out you have an if statement with two else attached to it, so the compiler doesn't understand what the second else is related to and throwing the error.
Maybe you wanted something like
if (newDeviation != 0) {
/* do something */
} else if (someCondition) {
/* do something different */
} else {
/* do something else */
}
If this is not the logic you want, please explain what you want to achieve, so we can help you better.
#user12372692
In order to achieve what you want, there are two ways to solve this -
A. if else condition making.
B. using switch case.
Way A :-
if else condition is written like following :-
if (condition 1) {
/* do something for condition 1 is true */
} else if (condition 2) {
/* do something for condition 2 is true */
} else {
/* do something for both condition 1 and 2 are false. */
}
so as per this your condition should be :-
if (newDeviation != 0) {
/* do something */
} else if (OtherCondition) {
/* do something*/
} else {
/* do something for both above two conditions are false */
}
Way B :-
switch(newDeviation){
case (newDeviation != 0 ) : {/* Do your work */}; break;
case (condition 2) : {/* Do your work */}; break;
case (condition 3) : {/* Do your work */}; break;
}

How can I exclude two pages from optimization using Autoptimize snippet given below

I hope someone can help me here. How can I use this Autoptimize snippet to exclude two pages from optimization. The code below excludes the page "https//www.nameofsite/submit-an-article"
add_filter(‘autoptimize_filter_noptimize’,’submit_noptimize’,10,0);
function submit_noptimize() {
if (strpos($_SERVER[‘REQUEST_URI’],’submit-an-article’)!==false) {
return true;
} else {
return false;
}
}
I want to exclude also another page-->"https//:www.nameofsite.com/upload/file" I modified and tried to use the code below but it gave me an error.
add_filter(‘autoptimize_filter_noptimize’,’submit_noptimize’,10,0);
function submit_noptimize() {
if (strpos($_SERVER[‘REQUEST_URI’],’submit-an-article’, 'upload-
file')!==false) {
return true;
} else {
return false;
}
}
Perhaps, I did something wrong with code? Hope someone can help me here. I am just a newbie. Not really familiar in php. Thank you in advanced.
Try this:
// Disable autoptimize on all pages with the words "term1" or "term2" in the URL
add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
function my_ao_noptimize() {
if (strpos($_SERVER['REQUEST_URI'],'term1')!==false || strpos($_SERVER['REQUEST_URI'],'term2')!==false) {
return true;
} else {
return false;
}
}

iOS 11 - How does one read/parse the NDEF Message from CoreNFC?

I have a bunch of tags that are URL tags that have the content "http://WEBSITE.com". Let's say WEBSITE is youtube so http://youtube.com. When I scan them on Android etc, it keeps the http or https.
I'm trying to scan these same tags using the Core NFC framework. I scan them and I get a bunch of bytes that I convert using NSSString initWithData with UTF8 Encoding. I get back \^Cyoutube.com. I want to get http://youtube.com.
How can I interept the payload to get what I need? If I'm to assume the http in front of the string, how am I supposed to know if it is http or https or even ftp?
Edit 1:
I'm having issues with the below answer code for pure text records. When making a text record for "hello world" I get the following outputs from the console:
2017-06-09 12:45:35.151806-0400 testNFC[2963:190724] Payload string:https://www.enhello world
2017-06-09 12:45:35.154959-0400 testNFC[2963:190724] Payload data:<02656e68 656c6c6f 20776f72 6c64>
To get the string I use
NSString *nfcMessage = [nfcType stringByAppendingString:[[[NSString alloc] initWithData:payload.payload encoding:NSUTF8StringEncoding] substringFromIndex:1]];
nfcType is the return from your function but for the None case I return #"";
I'm expecting to just get hello world.
For this, you will first need to make sure you have properly formatted NDEF tags. You can use an Android phone or one of these reader accessories along with an NDEF writing app.
Implement the following methods:
- (NSString *)getType:(NSData *)NDEFData {
NSString *firstByte = [self getFirstByte:NDEFData];
if ([firstByte isEqualToString:#"00"]) {
return #"None";
} else if ([firstByte isEqualToString:#"01"]) {
return #"http://www.";
} else if ([firstByte isEqualToString:#"02"]) {
return #"https://www.";
} else if ([firstByte isEqualToString:#"03"]) {
return #"http://";
} else if ([firstByte isEqualToString:#"04"]) {
return #"https://";
} else if ([firstByte isEqualToString:#"05"]) {
return #"tel:";
} else if ([firstByte isEqualToString:#"06"]) {
return #"mailto:";
} else if ([firstByte isEqualToString:#"07"]) {
return #"ftp://anonymous:anonymous#";
} else if ([firstByte isEqualToString:#"08"]) {
return #"ftp://ftp.";
} else if ([firstByte isEqualToString:#"09"]) {
return #"ftps://";
} else if ([firstByte isEqualToString:#"0A"]) {
return #"sftp://";
} else if ([firstByte isEqualToString:#"0B"]) {
return #"smb://";
} else if ([firstByte isEqualToString:#"0C"]) {
return #"nfs://";
} else if ([firstByte isEqualToString:#"0D"]) {
return #"ftp://";
} else if ([firstByte isEqualToString:#"0E"]) {
return #"dav://";
} else if ([firstByte isEqualToString:#"0F"]) {
return #"news:";
} else if ([firstByte isEqualToString:#"10"]) {
return #"telnet://";
} else if ([firstByte isEqualToString:#"11"]) {
return #"imap:";
} else if ([firstByte isEqualToString:#"12"]) {
return #"rtsp://";
} else if ([firstByte isEqualToString:#"13"]) {
return #"urn:";
} else if ([firstByte isEqualToString:#"14"]) {
return #"pop:";
} else if ([firstByte isEqualToString:#"15"]) {
return #"sip:";
} else if ([firstByte isEqualToString:#"16"]) {
return #"sips:";
} else if ([firstByte isEqualToString:#"17"]) {
return #"tftp:";
} else if ([firstByte isEqualToString:#"18"]) {
return #"btspp://";
} else if ([firstByte isEqualToString:#"19"]) {
return #"btl2cap://";
} else if ([firstByte isEqualToString:#"1A"]) {
return #"btgoep://";
} else if ([firstByte isEqualToString:#"1B"]) {
return #"tcpobex://";
} else if ([firstByte isEqualToString:#"1C"]) {
return #"irdaobex://";
} else if ([firstByte isEqualToString:#"1D"]) {
return #"file://";
} else if ([firstByte isEqualToString:#"1E"]) {
return #"urn:epc:id:";
} else if ([firstByte isEqualToString:#"1F"]) {
return #"urn:epc:tag:";
} else if ([firstByte isEqualToString:#"20"]) {
return #"urn:epc:pat:";
} else if ([firstByte isEqualToString:#"21"]) {
return #"urn:epc:raw:";
} else if ([firstByte isEqualToString:#"22"]) {
return #"urn:epc:";
} else if ([firstByte isEqualToString:#"23"]) {
return #"urn:nfc:";
}
return #"";
}
/*!
* gets the the NDEF content
*/
- (NSString *)getNDEFContent:(NSData *)data {
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return [dataString substringFromIndex:2];
}
/*!
* gets the first byte of the input NSData
*/
- (NSString *)getFirstByte:(NSData *)data {
return [[self dataToHexString:data] substringToIndex:2];
}
/*!
* transforms NSData to NSString
*/
- (NSString *)dataToHexString:(NSData *)data;
{
// get the length of the data
NSUInteger bytesCount = data.length;
if (bytesCount) {
// string with all the Hex characters
const char *hexChars = "0123456789ABCDEF";
// put bytes into an array and initialize the response array
const unsigned char *dataBuffer = data.bytes;
char *chars = malloc(sizeof(char) * (bytesCount * 2 + 1));
char *s = chars;
// go through data bytes making the transformations so a hex will literally translate to a string, so for example 0x0A will translate to "0A"
for (unsigned i = 0; i < bytesCount; ++i) {
// get hexChars character at binary AND between the current byte and 0xF0 bitwise to the right by 4 index and assign it to the current chars pointer
*s++ = hexChars[((*dataBuffer & 0xF0) >> 4)];
// get hexChars character at binary AND between the current byte and 0x0F index and assign it to the current chars pointer
*s++ = hexChars[(*dataBuffer & 0x0F)];
dataBuffer++;
}
*s = '\0';
// chars to string
NSString *hexString = [NSString stringWithUTF8String:chars];
free(chars);
return hexString;
}
return #"";
}
And call the getType method:
[self getType:yourNDEFPayloadNSData]
I'm assuming that all the methods are in the same class and,
that the payload NSData is NDEF compliant, but I modeled the code based on the NFCNDEFPayload payload
NFC NDEF message payload is much more complex than you expected. But CoreNFC does not support parsing NFC NDEF message payload. I created an open source parser VYNFCKit to parse payload. Example projects are available in both Objective-C and Swift. Check my tutorial https://medium.com/#vinceyuan/reading-and-parsing-nfc-tag-on-ios-11-60f4bc7a11ea
Regarding your EDIT1:
You are using the wrong Record Type.
You need to write a "Text Record", not a "URI Record".
If you have an Android Phone at hand, you could use tools like "NFC TagWriter by NFC" to write the correct record.
It might not be important for your use case, but think of interopability with Android Phones, resp. other apps. They would try to open "https://www.enhello world" instead of showing "Hello World", using EN encoding as a Text String.

how to set max resolution for each features in openlayers3

Hello i am trying to do different styles for different features and i got and working fine,now i want to set different resolution for different features.I tried doing this way but not working.Can u please Help this?
style: function (feature, resolution) {
//var test = (resolution >= 200) ? (feature.get('class') === 'xx') : '';
//resolution: test;
if (feature.get('class') === '---') {
max Resolution: 100;
return style1;
}
else if (feature.get('class') === 'xx')
{
return Style2;
}
else if (feature.get('class') === '---')
{
return style3;
}
else if(feature.get('class')==='ii')
{
return style4;
}
else if(feature.get('class')==='mm')
{
return style5;
}
},
You should be able to resolve this with simple boolean logic. Something like this:
style: function(feature, resolution) {
var class = feature.get('class');
if (resolution >= 200) {
if (class == 'xx') {
return style200xx;
} else if (class == 'xy') {
return style200xy;
}
} else if (resolution < 200) {
if (class == 'xx') {
return style0xx;
} else if (class == 'xy') {
return style0xy;
}
}
}
If you have many different cases, it might make sense to define a separate ol.layer.Vector for each resolution range, and use the same source for all layers. Inside the style functions, you will then only have to handle the feature class.

else condition is not executing?

in this following else if ,the last else condtion is not executing ?
Please help me
if (Flag==1)
{
...
}
else if ([totalBooksId containsObject:currentbook])
{
...
}
else if (![totalBooksId containsObject:currentbook])
{
...
} else {
...
}
All variable have some values but still else is not executing.
the above else statement is not executing at all? Please help me
This is will work
if(Flag==1){
if([OwnList containsObject:currentbook]){
if(fileExists) {
[self renameReadButton];
}else if(!fileExists){
[self renameDownloadButton];
}
[self renameLendButton];
}
}
else if([totalBooksId containsObject:currentbook]){
//Checking bought books
if([OwnList containsObject:currentbook]){
if(fileExists){
[self renameReadButton];
}else {
[self renameDownloadButton];
}
} else{
[self renameBuyButton];
}
}
else if(![totalBooksId containsObject:currentbook]) {
if([freeList containsObject:currentbook]){
if(fileExists){
[self renameReadButton];
}else{
[self renameDownloadButton];
}
} else{
[self renameBuyButton];
}
}
If the last else on an else-if block is not hit it usually means either of these:
One of the conditions in the initial if clause or the following else-if clauses was true
One of the evaluated conditions altered the program path (exception, stack corruption, etc.)
The code of the entire if-else block was never reached
In your case it seems to be the first case, because one of the else if conditions is the inverse of another.
Either ([totalBooksId containsObject:currentbook]) is true, or !([totalBooksId containsObject:currentbook]) is true. To hit the final else, both of them must be false.
You have three statement
else if([totalBooksId containsObject:currentbook]) // first
{
}
else if(![totalBooksId containsObject:currentbook]) // second
{
}
else { [self renameBuyButton]; } // last
Last statement is not executed because first and second catch all possible situations.
First catch [totalBooksId containsObject:currentbook] == true , second cath [totalBooksId containsObject:currentbook] == false and there is no third possibility.

Resources