Jump to content

9three

Members
  • Posts

    411
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

9three's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. aha! The book mentioned about dereferencing but I didn't get it until you explained it. Another issue: main(int argc, char *argv[]) { printf("%s", argv[1]); printf("%c", *argv[1]); } argv[1] is a string, but *argv[1] is a char (or int type). When I dereferenced argv at position 1, it gave me a char type. Is that correct? Thanks. btw, Why bother going to another forum when you're doing a good job?
  2. I'll search around for C forums but in the meantime... I do have a question: main(int argc, char *argv[]) { FILE *f = fopen("/home/9three/Desktop/test.txt", "a"); if (f == NULL) { printf("Unable to open file for writting."); return 1; } fprintf(*f, "Testing..\n"); return 0; } If you notice I'm passing a pointer to fprintf. This doesn't compile and the error is "expecting FILE type". But "f" was declared as FILE type to begin with. So "f" is a pointer and variable at the same time? If I pass *f then I'm passing a pointer. But if I pass "f" then I'm just passing a variable with a specific type? eehhh.. what? btw, the book I'm reading was published on 1988 http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628/ref=sr_1_1?ie=UTF8&qid=1295833514&sr=8-1
  3. Hi, Do you have a references into understanding memory (books, sites, etc)? I understand what you're saying but my knowledge is short on figuring out where the data actually exists in an address. Like how you figured out the address for *argv + 3. This makes perfect sense from your example of accessing a pointer and the data it contains: main(int argc, char *argv[]) { printf("%s", argv[1]); prtinf("%c", *argv[1]); } ...Yet I still feel a weak in this subject..
  4. Hi, Thanks for the response and taking the time on explaining it to me. I do understand it now. Thanks
  5. Hi, I'm currently learning C and I'm noticing between the book I'm reading and source code on the net of the following pattern: static void md5_hash(char *md5str, char *arg) { PHP_MD5_CTX context; unsigned char digest[16]; md5str[0] = '\0'; PHP_MD5Init(&context); PHP_MD5Update(&context, arg, strlen(arg)); PHP_MD5Final(digest, &context); make_digest(md5str, digest); } This is a snippet of mongo db source code. If you notice that one of the arguments is being passed a pointer as a parameter. But a few lines down, the variable is being passed to another function without the (*). I'm still a little confused. Aren't you suppose to always use the "*" when working with pointers within a function? I sometimes see the convention of always using the "*" and in other cases (like the code above), they don't bother with it. Which one is it? The book doesn't seem to explain the different approaches. Thanks EDIT: Here's another example that I wrote: void myFunction(char stuff[]) { printf("%s", stuff); } main(int argc, char *argv[]) { myFunction(*argv); return 0; } Arrays are passed by reference yet I cannot pass argv in main without the "*" as the compiler complains:
  6. Ah I had used explode but without trim and it didn't work correctly. Thanks
  7. Hi, I'm trying to match the following: preg_match('//', $_SERVER['REQUEST_URI'], $matches); print_r($matches); So that it looks like: If REQUEST_URI is /dev/example/me then it would match ->dev ->example ->me etc So I did '//' but its not working :-/ Can someone lend a hand? thanks.
  8. Hey, I'm trying to learn the ways of OO in JS. I'm trying to use prototype but it's not working right. The error message I get is "this.makeSortable is not a function" function tableSort(id) { this.tbl = document.getElementById(id); if (this.tbl && this.tbl.nodeName == 'TABLE') this.makeSortable(); } tableSort.prototype.makeSortable = function () { var headings = this.tbl.tHead.rows[0].cells; alert(headings); } Everything seems correct. So this is what I did: <a href="#" onclick="tableSort('sales'); return false;">Click</a> <table id="sales"></table>
  9. Turn on your error reporting, it will tell you why ini_set('display_errors', 1); error_reporting(E_ALL); Place it on top of everything that is PHP
  10. Your variable $title and $id are not being passed as parameters. public function editEntry($title, $id)
  11. Create a variable outside the foreach and it will be available for you after the loop is over. $str = ''; foreach ($arr as $strName) { if ($strName == 'Jason') $str = $strName; echo $strName; } echo $str; The variable $str now has the $strName value stored in it.
  12. I've looked into the php.ini option and it shows 10M for both... not sure what it could really be? :-/
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.