Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 326 327 [328] 329 330 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 882990 times)

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4905 on: September 14, 2013, 06:43:32 pm »

Well I got the loop to work with a typical character array, but not with an std::string.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4906 on: September 14, 2013, 09:43:36 pm »

Well I got the loop to work with a typical character array, but not with an std::string.

Do you have the code?
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4907 on: September 14, 2013, 09:52:12 pm »

http://pastebin.com/g62KPCMp

The strings in question are szY and szEndRead. The code is unintelligible and unfinished, and probably wouldn't work right if it were finished.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4908 on: September 14, 2013, 10:09:04 pm »

try replacing all the (char[] == char[]) and the (char[] != char[]) with (!strcmp(char[], char[])) and (strcmp(char[], char[])), since you cannot compare the values of a character array like that

For example, replace
Code: [Select]
while (szY != szEndRead)

with

Code: [Select]
while (strcmp(szY, szEndRead))

and

Code: [Select]
(szY == "armoring")

becomes

Code: [Select]
(!strcmp(szY, "armoring"))

strcmp will return zero of they are equal (because C loves being obtuse), so "!strcmp()" returns true if they are the same value.

Rather then using character arrays,  I would advise using std::string wherever possible (instead of what I said above), using std::getline to get a line from a ifstream. std::string actually works like you would expect.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #4909 on: September 15, 2013, 09:17:16 am »

Argh, PHP. It's a simple rest client and ONE table in SQL. This should not be so difficult, but instead it just 500s. Surrounding the entire thing in a try catch block doesn't work, 500. Putting echos everywhere reveals it dies whenever it tries to access a member function of a mysqli object. Any member function, like errno. Of any mysqli object I new up.

And this is just the GET that returns an image, not even the Create/Update/Delete side of things!

Even if the host/db name/user/password is incorrect, I should still get an error >.<

I could literally do this in five minutes in C#.
« Last Edit: September 15, 2013, 09:34:47 am by MorleyDev »
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4910 on: September 15, 2013, 11:37:02 am »

When I do this http://pastebin.com/HHYxn40x (changing Y and EndRead into std::strings and using strmcmp for my conditions), the compiler tells me that I cannot assign strY with a value from my ifstream and that I cannot use the strings as conditions, whether I use strcmp or ==. It says that "no conversion function from std::string and const char exists."
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4911 on: September 15, 2013, 12:38:45 pm »

Excuse me, as I make a tortured metaphor.

You asked how to eat meat with a spoon. It was suggested that you try using a fork, or to eat soup instead. So you began eating soup with a fork.

If you use std::string, then use == or !=.
If you use char arrays, then use strcmp;

Do not use std::string with strcmp, and do not use == and != with char arrays.
« Last Edit: September 15, 2013, 12:41:52 pm by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4912 on: September 15, 2013, 12:40:46 pm »

But == isn't working with the std::string either. Oh well I guess I'll go back to using character arrays and use strcmp. Thank you.
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4913 on: September 15, 2013, 12:42:58 pm »

But == isn't working with the std::string either. Oh well I guess I'll go back to using character arrays and use strcmp. Thank you.
That's odd.

And by odd I mean something is terribly broken and you shouldn't just ignore it.

EDIT:
Code: [Select]
    string strY;
    cin >> strY;
    if (strY == "string") cout << "Success!" << endl;
This for example doesn't work?
« Last Edit: September 15, 2013, 12:46:43 pm by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4914 on: September 15, 2013, 12:46:56 pm »

Well I can't see what. It's all there in the pastebin, so you could take a look there and see if you see anything. == won't work when comparing an std::string to a string in the file (such as "armoring") or in (strY != strEndRead). The compiler just says "no operator '==' or '!=' matches these operands."
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4915 on: September 15, 2013, 12:51:22 pm »

Well I can't see what. It's all there in the pastebin, so you could take a look there and see if you see anything. == won't work when comparing an std::string to a string in the file (such as "armoring") or in (strY != strEndRead). The compiler just says "no operator '==' or '!=' matches these operands."
"Armoring" doesn't work because you are using strcmp.
And the declaration of strEndRead isn't shown in the pastebin.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4916 on: September 15, 2013, 12:53:24 pm »

"Armoring" was a poor example, but it doesn't work for any of the streams that use ==. strEndRead is declared in the parenthesis of the function that the loop resides in.
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4917 on: September 15, 2013, 12:57:49 pm »

"Armoring" was a poor example, but it doesn't work for any of the streams that use ==. strEndRead is declared in the parenthesis of the function that the loop resides in.
Streams? You mean strings?

I didn't mean its location. Is strEndRead a char array?
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4918 on: September 15, 2013, 12:58:22 pm »

Argh, PHP. It's a simple rest client and ONE table in SQL. This should not be so difficult, but instead it just 500s. Surrounding the entire thing in a try catch block doesn't work, 500. Putting echos everywhere reveals it dies whenever it tries to access a member function of a mysqli object. Any member function, like errno. Of any mysqli object I new up.

And this is just the GET that returns an image, not even the Create/Update/Delete side of things!

Even if the host/db name/user/password is incorrect, I should still get an error >.<

I could literally do this in five minutes in C#.

What does the server's error log say?  Might help give a clue.

Otherwise I'm suspecting the MySQLi library might be disabled or compiled in from a different, incompatible, version of PHP somehow.  I would expect that to crash immediately when the service starts, or at the very least when you create a new instance of any of the objects.

Just for fun, maybe you could try using PDO instead?  I don't think MySQLi is deprecated yet like the old MySQL functions are, but PDO is definitely the preferred way to do this now.
Logged
Through pain, I find wisdom.

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4919 on: September 15, 2013, 12:59:29 pm »

"Armoring" was a poor example, but it doesn't work for any of the streams that use ==. strEndRead is declared in the parenthesis of the function that the loop resides in.
Streams? You mean strings?

I didn't mean its location. Is strEndRead a char array?
yes I meant strings and no it's an std::string.
Logged
Pages: 1 ... 326 327 [328] 329 330 ... 796