Jump to content

9three

Members
  • Posts

    411
  • Joined

  • Last visited

    Never

Everything posted by 9three

  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? :-/
  13. I don't think the problem is the code itself as it works fine for 95kb files or less. I'm thinking its a php.ini problem??
  14. Hi, I have an uploader checking if the file is greater than 5mbs, if so display an error but it's not displaying an error nor is it uploading. It seems it works correctly for files around 200kb or less, then it just seems to stall... if ($_FILES['file']['size'] > 5242880 || $_FILES['file']['size'] <= 0) echo 'File size too big or too small'; elseif ($_FILES['file']['error'] != 0) echo 'There was a problem with your upload'; Actually more around 95kb.
  15. Yea I already have something simliar to that I just thought there might be something like a UNIQUE Constraint but for two columns. thanks anyway
  16. Hi, I'm wondering if its possible to have 2 columns and have the data in them (integers) be unique to each other. Example: Column 1 - Column 2 1000 - 4522 Never again can that combination exist or 4522 - 1000 exist unless the row is deleted. Is this possible?
  17. Change your SQL to ASC instead of DESC
  18. Your code does not work if the x is less than 5, that's why I check if its less than 5. If it is, then I do a different for loop.
  19. It's about the same except you dont have a less than or equal to. But thank you anyway.
  20. Ok I figured it out with the code you guys provided. Here is what I did. Any recommended improvement is always accepted $current = 16; if ($current <= 5) { for($i = 1;$i < $current; $i++) { echo $i.' '; } } else { for($i = $current - 5;$i <= $current - 1 && $i > 0; $i++) { echo $i.' '; } } echo ' Current:'.$current;
  21. Actually I take that back. I went with your code Alex and it displays it wrong. if current is 14 then output is: 13 12 11 10 9 14 It should be: 9 10 11 12 13 14
×
×
  • 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.