I'm working with processing 2.2.1, and I am 90% sure that this is syntactically correct. I keep getting an error explaining that it is incorrect with an "unexpected token: int".
void growEllipse(int ellipseHW){
if(int i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
I have tried moving the int to within the function, like so (check below) but then I get an error saying that it is "expecting RPAREN, found ';'".
void growEllipse(int ellipseHW){
int i;
if(i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
}
This is rather frustrating because it seems syntactically correct.
Can anybody help me figure it out?
It looks like you're trying to use a for loop, not an if statement:
for(int i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
More info on the for loop can be found in the Processing reference.
Try using a 'for' statement instead of an 'if' statement.
Related
When does a C++ program throw this error message:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
Aborted (core dumped)
I was trying an algorithm problem on a website.
My function was:
int stringSimilarity(string s)
{
int size=s.size(), sum=0;
for(int i=0; i<size; i++)
{
string sub_str; int temp_sum=0;
//Creating a substring for comparison
for(int j=i, l=0; j<size, l<size-i; j++, l++)
{
sub_str.at(l)=s.at(j);
}
if(sub_str.at(0)==s.at(0))
{
temp_sum++;
int k=1;
while(sub_str.at(k)==s.at(k))
{
temp_sum++;
k++;
}
}
sum=sum+temp_sum;
}
return sum;
}
While running sample test cases, I got the error message I showed above. Can someone please tell me where am I going wrong?
EDIT:
Made the question to the point. In the original question, I had asked why my program was not compiling. But as many pointed out, it is not a compilation error, but a run-time error thrown by the program.
From documentation of std::string::at()
The function automatically checks whether pos is the valid position of
a character in the string (i.e., whether pos is less than the string
length), throwing an out_of_range exception if it is not.
In here, sub_str is an empty string (length 0), but you try to access it in the first line of your inner loop:
sub_str.at(l)=s.at(j);
One way to overcome it could be to initialize the string to have the same length of s, and edit it in place.
I have faced the same issue when I was doing code on HackerRank,So let me tell you what was my mistake:
I was taking one extra input which was not mentioned in test case so when i removed that my problem got solved.
Program was saying user will give two queries and i have to work on those queries but I was taking the query numbers too.
It was like
cin >> query;
And then i was taking 2 query q1 and q1 so during run time compiler said Abort Called and when i remove this(cin >> query;) line,My program worked fine.
FindPattern Function looks like this
DWORD FindPattern(DWORD base ,char *module, char *pattern, char *mask)
{
MODULEINFO mInfo = GetModuleInfo(module);
DWORD size = (DWORD)mInfo.SizeOfImage;
DWORD patternLength = (DWORD)strlen(mask);
for (DWORD i = 0; i < size - patternLength; i++)
{
bool found = true;
for (DWORD j = 0; j < patternLength; j++)
{
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}
if (found)
{
return base + i;
}
}
return NULL;
}
and i'm using use the function like this
DWORD aAddy = FindPattern(BaseAddress,(char*)("ros.exe"),
const_cast<LPSTR>("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\0x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFA\x44\x00\x00\x00\x3F\x00\x00\x00\x00"),
const_cast<LPSTR>("???????????????x??????????????????????????????????????????????????????????????????????xx???x????"));
while debugging i got error on j = 15 and mask[j] = 'x'
the exception thrown show access violation reading location "base"
can someone help me what is wrong with j = 15 or i just wrong passing the parameters?
i cant pass the char* mode just like ("ros.exe") its give me error
cant convert argumen char* to char*.
Gee that code looks familiar :P
You get Access Violation on 'base' because you do not have read permissions on 'BaseAddress' which you pass in as the 'base' argument. We do not know what 'BaseAddress' is because you don't include how you assign the value of that variable in the code you posted. Perhaps it is uninitialized or you need to use VirtualProtect() to get read permissions. I would assume you don't initialize it or are passing in the wrong address.
It reads from 'base' the first time when j=15 because this is the first element of the char array that is not a wildcard, meaning your code doesn't read from 'base + i + j' until a non-wildcard is found that is why it doesn't happen until j=15.
The original source code includes this line to get the base address of the module, but you have modified/removed it.
DWORD base = (DWORD)mInfo.lpBaseOfDll;
Alternatively you can use this to get the base address of the executable
DWORD base = (DWORD)GetModuleHandle(NULL);
Once you properly define base I think your code will work just fine
.proto file structure
message repetedMSG
{
required string data = 1;
}
message mainMSG
{
required repetedMSG_id = 1;
repeated repetedMSG rptMSG = 2;
}
I have one mainMSG and in it too many (suppose 10) repetedMSG are present.
Now i want to delete any particular repetedMSG (suppose 5th repetedMSG )from mainMSG. For this i tried 3 ways but none of them worked.
for (int j = 0; j<mainMSG->repetedMSG_size(); j++){
repetedMSG reptMsg = mainMsg->mutable_repetedMSG(j);
if (QString::fromStdString(reptMsg->data).compare("deleteMe") == 0){
*First tried way:-* reptMsg->Clear();
*Second tried Way:-* delete reptMsg;
*Third tried way:-* reptMsg->clear_formula_name();
break;
}
}
I get run-time error when i serialize the mainMSG for writing to a file i.e. when execute this line
mainMSG.SerializeToOstream (std::fstream output("C:/A/test1", std::ios::out | std::ios::trunc | std::ios::binary)) here i get run-time error
You can use RepeatedPtrField::DeleteSubrange() for this. However, be careful about using this in a loop -- people commonly write code like this which is O(n^2):
// BAD CODE! O(n^2)!
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
message.mutable_foo()->DeleteSubrange(i, 1);
--i;
}
}
Instead, if you plan to remove multiple elements, do something like this:
// Move all filtered elements to the end of the list.
int keep = 0; // number to keep
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
// Skip.
} else {
if (keep < i) {
message.mutable_foo()->SwapElements(i, keep)
}
++keep;
}
}
// Remove the filtered elements.
message.mutable_foo()->DeleteSubrange(keep, message.foo_size() - keep);
I've been searching for scripts and stuff to look up but, seems like google api has been changed too much or I'm dumb and doesn't know how to execute old scripts and make them work.
I keep getting these errors Parsing error... Yahoew this helps to a lot. Not knowing what line. So I made my own.
function amountOfColors(color, range){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var orgColor = ss.getRange(color).getBackground();
var range = ss.getRange(range);
var x = 0;
Logger.log("I was here before the loop.");
for (var i; i < range.getNumRows(); i++) {
Logger.log("Entered Row loop");
for (var j; j < range.getNumColumns(); j++) {
Logger.log("Entered Columns loop");
var curCell = range.getCell(i, j);
Logger.log("curCell is : " & curCell);
if(curCell.getBackground() == orgColor) {
Logger.log("curCell color is : " & curCell.getBackground());
x++;
}
}
}
Logger.log("END");
return x;
};
As you can see I pretty much made it log for every thing. However this is what it returns in the logfile:
[14-02-20 04:00:53:445 CET] I was here before the loop.
[14-02-20 04:00:53:445 CET] END
Not even touching my loop?
All I want this script to is to take a color from a original position and then find how many cells has that color and return it. Really simple script.
Hope someone can enlighten me on this one. I've tried to install scripts from the script gallery that does similar but they return errors too.
Here's a picture of a setup:
http://b.imgdrp.com/PCoT.PNG - I realise it says B33:B35, but even with A it doesn't work.
Adding my own answer in case someone would have similar problem.
function amountOfColors(color, range){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]
var orgColor = sheet.getRange(color).getBackground();
var range = sheet.getRange(range);
var x = 0;
for (var i = 1; i <= range.getNumRows(); i++) {
for (var j = 1; j <= range.getNumColumns(); j++) {
var curCellColor = range.getCell(i,j).getBackground();
if(curCellColor == orgColor)
x++;
}
}
return x;
};
Other than this I changed the way I called my function:
instead of:
=amountOfColors("A35", "A33:A35")
you need to use:
=amountOfColors("A35"; "A33:A35")
As you can see semi-colon instead of comma.
My apologies for posting and fixing it so fast, seems like all I needed was that 1 extra hour to get crafty. At least hope someone might gain something from this.
If there is any questions about the code feel free to add a comment, I'll try to explain.
Best Regards Qvintus.
I'm been trying to poll from a set of named-pipes for a little while now and i keep getting an immediate response of POLLNVAL on any named pipe file descriptor. After finding this blog post about broken polling in OS X I'm pretty certain that this is a b-u-g bug in OS X.
I'm already planning on switching my code to using UDP sockets, but i wanted to ask SO for verification about this a) so that I'm sure it's really broken, and b) for documentation purposes.
Here is a stripped down version of the code I wrote (although the code in the link above, which I tested, spells it out pretty well):
#includes
...
....
#
static const char* first_fifo_path = "/tmp/fifo1";
static const char* second_fifo_path = "/tmp/fifo2";
int setup_read_fifo(const char* path){
int fifo_fd = -1;
if( mkfifo(path, S_IRWXU | S_IRWXG | S_IRWXO) )
perror("error calling mkfifo()... already exists?\n");
if((fifo_fd = open(path, O_RDONLY | O_NDELAY)) < 0)
perror("error calling open()");
return fifo_fd;
}
void do_poll(int fd1, int fd2){
char inbuf[1024];
int num_fds = 2;
struct pollfd fds[num_fds];
int timeout_msecs = 500;
fds[0].fd = fd1;
fds[1].fd = fd2;
fds[0].events = POLLIN;
fds[1].events = POLLIN;
int ret;
while((ret = poll(fds, num_fds, timeout_msecs)) >= 0){
if(ret < 0){
printf("Error occured when polling\n");
printf("ret %d, errno %d\n", ret, errno);
printf("revents = %xh : %xh \n\n", fds[0].revents, fds[1].revents);
}
if(ret == 0){
printf("Timeout Occurred\n");
continue;
}
for(int i = 0; i< num_fds; i++){
if(int event = fds[i].revents){
if(event & POLLHUP)
printf("Pollhup\n");
if(event & POLLERR)
printf("POLLERR\n");
if(event & POLLNVAL)
printf("POLLNVAL\n");
if(event & POLLIN){
read(fds[i].fd, inbuf, sizeof(inbuf));
printf("Received: %s", inbuf);
}
}
}
}
}
int main (int argc, char * const argv[]) {
do_poll(setup_read_fifo(first_fifo_path), setup_read_fifo(second_fifo_path));
return 0;
}
this outputs:
$ ./executive
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
...
ad nauseam.
Anybody else run into this? This is a real bug right?
This seems to be a genuine bug. It works as expected on Linux and OpenBSD and fails as you describe on OS X.
OSX 10.4.1, I can confirm the behaviour. The same code works fine (as long as timeout messages are fine) on Linux. All the evidence, including this - http://www.virtualbox.de/changeset/12347 - suggests that there is a real problem.
Yup, known bug. I think the poll breakage is only since 10.4, we had to deal with it in Fink. Glib's configure.in has a test for this, so you can be sure that you're not imagining it. (Well, not precisely this, glib tests for poll on devices, not fifos.)