Jump to content

rubing

Members
  • Posts

    366
  • Joined

  • Last visited

    Never

Posts posted by rubing

  1. I don't understand.

     

    In this code snippet there is a function called getline which accepts 2 parameters:

     

    line : which is defined as character array, but is initially empty

    MAXLINE : which is the max length of a line for our testing purposes [1000 characters; prevents overflow]

     

    getline returns the number of characters in the line.

     

    It should not alter either of the parameters MAXLINE or line, except within the scope of that function.  Am I incorrect?

     

     

      while ((len=getline(line,MAXLINE)) > 0)
        if (len > max) {
          max=len;
          copy(longest,line);
        }
    

  2. Hey, (corbin I assume  ;))

     

    I am working through another example.  This is a small program composed of 2 functions which takes a standard input of many lines and determines the longest.  It then prints the longest.  I do not understand how the second function called copy is obtaining the character array for the longest line.  I am thinking that maybe there is something different about the scope of parameters in C from php, which makes this possible...i don't know. your wise counsel is appreciated! 

     

    Here is the code:

     

    #include <stdio.h>
    #define MAXLINE 1000
    
    int getline(char line[], int maxline);
    void copy(char to[],char from[]);
    
    main()
    {
      int len;
      int max;
      char line[MAXLINE];
      char longest[MAXLINE];
    
      max=0;
    
      while ((len=getline(line,MAXLINE)) > 0)
        if (len > max) {
          max=len;
          copy(longest,line);
        }
      if (max > 0)
        printf("%s", longest);
      return 0;
    }
    
    int getline(char s[], int lim)
    {
      int c,i;
    
      for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
        s[i]=c;
      if (c== '\n') {
        s[i] = c;
        ++i;
      }
      s[i]='\0';
      return i;
    }
    
    void copy (char to[], char from[])
    {
      int i;
    
      i = 0;
      while ((to[i]=from[i])!='\0')
        ++i;
    }
    
    

  3. I have the following code that determines the number of digits (0, 1, 2, 3, etc..), whitespace, and characters in a file.  I don't understand why the line in red (++ndigit[c-'0'];) can't be written merely as ++ndigit[c]?

     

    Thanks!

     

     

    #include <stdio.h>
    
    main()
    {
      int c,i,nwhite,nother;
      int ndigit[10];
    
      nwhite=nother=0;
    
      for (i=0; i<10;++i)
        ndigit[i]=0;
    
      while ((c=getchar())!=EOF)
        {
          if (c>='0' && c<='9')
    [b][color=red]++ndigit[c-'0'];[/color][/b]
          else if (c == ' ' || c=='\n' || c=='\t')
    ++nwhite;
          else
    ++nother;
        }
    
      printf("digits =");
      for (i=0; i<10; ++i)
        printf(" %d",ndigit[i]);
      printf(",white space=%d,other=%d\n",nwhite,nother);
    }
    

  4. I am following along with exercises from a book (C Programming), and one of the examples doesn't seem to be working.  I believe it's supposed to print the number of characters you enter, but it doesn't do anything.  Is there something wrong with my code?

     

    #include <stdio.h>
    main()
    {
      long nc;
    
      nc=0;
    
      while (getchar() != EOF) 
        ++nc;
    
      printf("%ld\n",nc);
    }
    

  5. If cl_id is a number than you don't need quotes around it in your query. that's probably the problem...sql trying to compare a string to an integer

     

    Try that and then if that doesn't work start profiling it by throwing some echo statements in there???

     

    <?php
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    include '../library/config.php';
    include '../library/opendb.php';
    
       $cl_ID = $_GET['cl_ID'];
    
       if(isset($_POST['submit']))
      {
    
          $cl_course = addslashes($_POST['cl_course']);
          $cl_day = addslashes($_POST['cl_day']);
    
             $result = mysql_query("UPDATE classes SET cl_course='$cl_course', cl_day='$cl_day' WHERE cl_ID='$cl_ID' ",$conn);
    
    }
    elseif($cl_ID)
    {
    
            $result = mysql_query("SELECT * FROM classes WHERE cl_ID='$cl_ID' ",$conn);
            while($myrow = mysql_fetch_assoc($result))
                 {
    
                    $cl_course = $myrow["cl_course"];
    echo $cl_course;
                    $cl_day = $myrow["cl_day"];
    echo $cl_day;
    ?>
    
    <form method="post" action="<?php echo $PHP_SELF ?>">
    <table>
    <input type="hidden" name="cl_ID" value="<? echo $myrow['cl_ID']?>">
    <tr>
    <td>Course:</td><td><input name="cl_course" size="40" maxlength="255" value="<? echo $cl_course; ?>" /></td></tr>
    <tr>
    <td>Day: </td><td><input name="cl_day"  size="40" maxlength="255" value="<? echo $cl_day; ?>" /></td></tr>
    </table><br />
    <div align="center"><input type="submit" name="submit" value="Update Class" /></div>
    </form>
    <?
                  }
    
      }
    ?>
    

  6. yes this is very simple.  again: 

     

    1. you store all your info in a database. 

    2. you query the database & store the resulting info in variables using php. 

    3. you populate your form with these variables.

     

    You should probably start by figuring out how to connect to your DB using php.

     

    I don't know what else to tell you dude i am giving you the theoretical background. now you have to get a book and start working through it or pay somebody and they will do it for you. There are plenty of people here who would set something up like that for you very quickly.

  7. of course you can. you should get a php mysql book. 

     

    you need to do the following

     

    1. connect to and query your DB for the info you want via php.

     

    2.  return the result as an associative array

     

    3.  echo the values were you want them

     

    don't ask me to write the program for you.  start working on step 1 and ask us for help when you need it!

     

  8. sounds like you should just make a table with a column containing a list of valid product keys? And then just look up to see if somebody gives you a valid product key. I wouldn't be too worried for now about multiple people sharing a key or something like that. You can code up some protections against that later.  For now, just concentrate on getting your webapp out there and making money.  you'll probably just sell it to somebody else if it really works.

  9. Hey all I have an interesting question, so figured I would post it here.  I feel I would benefit from learning a new language, either C or javascript. 

     

    There are a number of practical reasons for these choices:

     

    In javascript there's a bunch of Ajaxy and UI stuff I'd like to do to improve my site and web apps.

     

    C would help me customize my server. it'd help me compile and set things up.  I could start using the firebird db and write my own functions for it.

     

    Given my php background, which language would you reccomend learning next.  My hunch is that php is based off of C, so that might be easier?  I also like the idea of being able to hack the guts of php.

×
×
  • 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.