Tuesday, May 22, 2012

Why doesn't VC++ 2010 Express require stdio.h in this program but gcc++ does?

I have the following code



#include <iostream>

using namespace std;

void WaitForEnter()
{
while(1)
{
if('\n' == getchar())
{
break;
}
}
}

int main()
{
cout<< "Press Enter to Exit... ";
WaitForEnter();
}


This compiles on Microsoft Visual C++ 2010 Express and does what I expected. On Ubuntu using code::blocks and gcc++ 4.7 the build fails with the following error: 'getchar' was not declared in this scope. If I add the line #include "stdio.h", the program compiles and runs with the expected behavior. Why does this program compile using MVC++ 2010 Express without stdio.h but not for code::blocks with gcc++ 4.7 on Ubuntu.





How can a web shared local html file be opened via Safari?

From system preferences/Internet & Wireless/Sharing I selected Web Sharing then clicked on Open Personal Website Folder, and there is an existing index.html file there with address



http://my ip address/~myusername/sites/index.html if online or if offline then
http://MacBook-Pro/~myusername/sites/index.html


But if I try to open these URLs from Safari it doesn't work, perhaps as expected if using the http scheme, so I tried with file:// instead but it says



"No file exists at "/~myusername/sites/index.html". But the file does exist there, I can see it.



Are there some tricks involved in getting Safari to see this file?





GetElementsByTagName alternative to DOMDocument

I am creating an HTML file with DOMDocument, but I have a problem at the time of the search by the getElementsByTagName method. What I found is that as I'm generating the hot, does not recognize the labels that I inserted.



I tried with DOMXPath, but to no avail :S



For now, I've got to do is go through all the children of a node and store in an array, but I need to convert that score DOMNodeList, and in doing



return (DOMNodeList) $ my_array;


generates a syntax error.



My specific question is, how I can do to make a search for tags with the getElementsByTagName method or other alternative I can offer to achieve the task?



Recalling that the DOMDocument I'm generating at the time.



If you need more information, I'll gladly place it in the question.



Sure Jonathan Sampson.



I apologize for the editing of the question the way. I did not quite understand this forum format.



For a better understanding of what I do, I put the inheritance chain.



I have this base class



abstract class ElementoBase {
...
}


And I have this class that inherits from the previous one, with an abstract function insert (insert)



abstract class Elemento extends ElementoBase {
...
public abstract function insertar ( $elemento );
}


Then I have a whole series of classes that represent the HTML tags that inherit from above, ie.



class A extends Elemento {
}
...


Now the code I use to insert the labels in the paper is as follows:



public function insertar ( $elemento ) {

$this->getElemento ()->appendChild ( $elemento->getElemento () );
}


where the function getElemento (), return a DOMElement



Moreover, before inserting the element do some validations that depend on the HTML tag that is to be inserted,
because they all have very specific specifications.



Since I'm generating HTML code at the same time, it is obvious that there is no HTML file.



To your question, the theory tells me to do this:



$myListTags = $this->getElemento ()->getElementsByTagName ( $tag );


but I always returns null, this so I researched it because I'm not loading the HTML file, because if I



$myHtmlFile = $this->getDocumento ()->loadHTMLFile ( $filename );
$myListTags = $myHtmlFile->getElementsByTagName ( $etiqueta );


I do return the list of HTML tags



If you need more information, I'll gladly place it in the question.





Understandable explanation to a simple file writer?

I have been looking around the internet for a long time and i STILL havent found a sensible answer as to making a program that creates a file in a directory (Such as C:). So if you could please explain to me how i would do this it would be greatly appreciated! Thanks!
EDIT-Im using java and i want to write a text document. Probably should have said that before :/





TestFlight build, network calls don't work

This is driving me batty. I've used TestFlight on a few occasions with great success, but this time around I'm having issues.



The archive works, uploads to TestFlight just fine, installs to the target device just fine, but my network calls NEVER execute. E.G. You never see any network activity from the device and watching the backend the calls never arrive.



Debug builds on the same device work as expected.





Java Script code not running well on ie9

I have this code it suppose to display an ad for 10 seconds then load a embed code.
the thing is that it's working fine on firefox but not ie 9 it's run the ad and the embed code in the same time in the background.
Is there is anyway to resolve this problem.
the code is attached.
thank you



<script type="text/javascript">
var nbsec=10;
var c=0;
var t;
var timer_is_on=0;
var sum=0;
function timedCount()
{
c=c+1;
t=setTimeout("timedCount()",1000);
sum=nbsec-c;
document.getElementById('chrono').innerHTML="<br>Loading .. Please wait "+sum+"secondes";
if(c == nbsec){
stopCount();
document.getElementById('mypub').style.visibility = 'hidden';
document.getElementById('mygame').style.visibility = 'visible';
document.getElementById('mygame').style.display ='block';
document.getElementById('mygame').style.height = 'auto';
document.getElementById('mypub').style.height = '0px';
document.getElementById('mypub').style.padding = '0px';
document.getElementById('mypub').innerHTML="";
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>

<table border ="2" align="center" color="F2FC7E"><tr><td>
<div id="mypub" style="visibility: visible; text-align:center; padding:20px;">

<script>
..............
</script>

<div id="chrono" style="color:#FFF;"></div>
</div>
<div id="mygame" style="visibility: hidden;display:none; height:0px">
<param name="initial_focus" value="true">
<applet>
........................
</applet>
</div>
</td></tr></table>
</div>
<script type="text/javascript">
timedCount();
</script>




accessing vars inside a js function

So I have a psudo "Class" with functions and vars inside of it
for this question I'll just use an example:



function MyClass()
{
this.a = 0;
this.b = function(c)
{
this.a += c;
}
}


then when I go to use it later i'll do this:



var myObject = new MyClass();
myObject.b(3);
myObject.b(5);


but when I do this:



console.log("A: " + myObject.a);


I get:



A: 0


What am I doing wrong?