Thread: Programming software for my job

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    13

    Programming software for my job

    Hello, I am James and I am new to programming and to the forum. I have always had a passion for coding. I am 24, I work in Texas as a Patrol Deputy for the County. I have decided to learn C programming language, as my starting language. I have been taking tutorials on the site and have learned the basic commands. I am trying to design a program for myself out in the field that brings information up as i type a statute for an offense. My questions are as followed :
    (1)Is there are a command besides printf();, that displays a text. The Texas statutes are quite lengthy and using printf(), is very time consuming.

    (2)Is there a command that allows you to pull information up by using more then one character such as a,b,c. For example , if i search Marijuana , it would pull a Marijuana offense up.

    Thanks James.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by James Longoria
    I am trying to design a program for myself out in the field that brings information up as i type a statute for an offense.
    This is merely a learning exercise, or do you actually intend to use it in the field?

    Quote Originally Posted by James Longoria
    (1)Is there are a command besides printf();, that displays a text. The Texas statutes are quite lengthy and using printf(), is very time consuming.
    The time consuming part would presumably be the typing out of the text from say, the hardcopy book, or copying it from a state website and reformatting it for printf (and/or storage with respect to your program). Unfortunately, no matter what you do, you cannot avoid this part of getting the text into a form usable by your program.

    One practical problem that you may face is that if you are using a command shell (command prompt/window/whatever it is really supposed to be called), then displaying a wall of text would not be very good because it would be difficult to read. This may mean implementing some kind of page system for the text, if one is not available in the command shell.

    Thinking further, you might eventually develop a GUI for this... though if I were you I would develop a mobile website instead so fellow officers can easily access the statutes by phone, if this has not already been developed. Of course, this is beyond the scope of a learning exercise for C.

    Quote Originally Posted by James Longoria
    (2)Is there a command that allows you to pull information up by using more then one character such as a,b,c. For example , if i search Marijuana , it would pull a Marijuana offense up.
    This depends on how you are storing the text. For example, you might use a database engine and store the text along with indexed keywords, then you search for the keywords, and from there retrieve the corresponding text.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by James Longoria View Post
    For example , if i search Marijuana , it would pull a Marijuana offense up.
    I don't find marijuana offensive.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Thanks for the information laserlight. The project is a learning exercise and will be used out in the field. As for the mobile websites, it would be as bad as the Command Prompt window. A majority of Officer's know the arrestable offense as they are arresting there defendant. The problem out in the field for rookies and Officer's who do not know the statutes by heart, comes to play when you are booking the defendant. A majority of Texas jails block cell phone signal and agency's do not allow Officer's to use there in car computer for internet. I am trying to make a program that makes it easier for Officer's during the booking process. It is such a pain to always have to look up the elements of a crime and statute title. The program will basically have a search index or a statute code option that will bring the Probable cause for the arrest and offense tittle. A lot of the app's that have the Texas statues are outdated,slow and charge from $2-$5 for basic information.

  5. #5
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Quote Originally Posted by oogabooga View Post
    I don't find marijuana offensive.
    § 481.121. OFFENSE: POSSESSION OF MARIHUANA. (a) Except
    as authorized by this chapter, a person commits an offense if the
    person knowingly or intentionally possesses a usable quantity of
    marihuana.
    (b) An offense under Subsection (a) is:
    (1) a Class B misdemeanor if the amount of marihuana
    possessed is two ounces or less;
    (2) a Class A misdemeanor if the amount of marihuana
    possessed is four ounces or less but more than two ounces;
    (3) a state jail felony if the amount of marihuana
    possessed is five pounds or less but more than four ounces;
    (4) a felony of the third degree if the amount of
    marihuana possessed is 50 pounds or less but more than 5 pounds;
    (5) a felony of the second degree if the amount of
    marihuana possessed is 2,000 pounds or less but more than 50 pounds;
    and
    (6) punishable by imprisonment in the institutional
    division of the Texas Department of Criminal Justice for life or for
    a term of not more than 99 years or less than 5 years, and a fine not
    to exceed $50,000, if the amount of marihuana possessed is more than
    2,000 pounds.

  6. #6
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I'm glad you're getting all the evil mariHuana people off the streets.
    I feel so much safer.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  7. #7
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Quote Originally Posted by oogabooga View Post
    I'm glad you're getting all the evil mariHuana people off the streets.
    I feel so much safer.
    They are not using the classic natural Marijuana, now days they are smoking Synthetic Marijuana. The Synthetic Marijuana is just a herbal incense with a lot of other chemicals that actually fry there brain.

  8. #8
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by James Longoria View Post
    They are not using the classic natural Marijuana, now days they are smoking Synthetic Marijuana. The Synthetic Marijuana is just a herbal incense with a lot of other chemicals that actually fry there brain.
    That's not what I grow. And it sounds like you might have been smoking a little of your imaginary "synthetic" marijuana.

    Naaaaah, I'm just yankin' yer chain!
    G'nite.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    offense. My questions are as followed :
    (1)Is there are a command besides printf();, that displays a text. The Texas statutes are quite lengthy and using printf(), is very time consuming.

    (2)Is there a command that allows you to pull information up by using more then one character such as a,b,c. For example , if i search Marijuana , it would pull a Marijuana offense up.
    1) Yes, there is. It isn't a "command", it's built into the logic of loops.

    2) Yes. If you'll post a couple more (they can be short) statutes not for marijuana, I'll make a short example of one way it could be done.

    You want the entire statute for that keyword, printed up, correct?

  10. #10
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Several years ago, I think it was late summer of 2008, I was driving along the interstate late at night. It wasn't a great night for driving: the rain had been relentlessly falling for most of the day and the dark of the night made it difficult to drive. My wind-shield wiper blades thronged back and forth like a metronome vainly attempting to wipe the river of water away. My headlights illuminated the raindrops in dazzling displays of falling pinpricks of jewelled light. Struggling to overcome the hypnotic effect of the windscreen wipers I wound my window down slightly to see if fresh air would pull be back from the brink of sleep. For a few moments the water being thrust through the open window onto my arm and face seemed to revive me, however the wipers once again began to lull my mind into a dangerous state of drowsiness. Even in the best of circumstances, driving when drowsy is completely negligent, inviting disaster to inflict myself and others. On a dark and dismal night with visibility compromised by the severe weather it was insanity. The open window was not helping me pull myself out of the dangerous state, so I pulled onto the verge and lit a cigarette. Perhaps a rest was the most sensible thing to do and maybe the rain would ease before I re-embarked; I did not however intend to sleep, my cargo was much too valuable. Lying back into the car seat I took a long drag of the cigarette and exhaled. The smoke inside the car clung to the ceiling, undulating and expanding mimicking what the storm clouds outside must surely be doing. I finished the cigarette and let my eyes close for a moment.

    There was a steady knocking sound and a voice in the distance. I couldn't work out what the voice saying but the knocking continued. Startled, my eyes flashed open, blinking at the bright light shining into my window. Had I fallen asleep?

    "Sir, please wind down the window," the voice was saying. Groggily and without much thought I wound the window down. The rain had eased and was now a gentle shower. A slither of light on the horizon indicated that dawn was approaching. Had I slept that long?

    "Hello," I said, still struggling to shake the haze of sleep from my mind.

    "Sir, have you been drinking?" the person asked. I now realised it was a police officer and he was staring at me enquiringly, his flashlight scanning the interior of my car before coming back to rest on my face. I glanced at my rearview mirror and noticed the flashing red and blue lights behind me.

    "Umm, no," I said. "I haven't had a drink for months, I only smoke marijuana now."

    The officer frowned. Aiming his flashlight at the rear seat of my car illuminated the several hundred vacuum-sealed packages occupying the back seat of my car. Each of the packages contained a greenish substance and each package had a sticker on it reading "Marijuana 5kgs".

    "Sir, is that 1000kgs of Marihuana on the back seat of your car?" he asked somewhat accusingly.

    I'd been woken up from a nice sleep and was feeling a bit grumpy but decided to answer less abrasively than I may have. "What do the labels say?" I asked turning around and looking at the packages as if I'd just noticed them.

    "They say, 'Marijuana 5kgs'" the officer said.

    "Yes, I remember putting them there now. I'm taking them to a friends house."

    "This much marihuana is a felony!" the officer exclaimed. "You're evil incarnate!" he muttered as he spoke into his shoulder asking for backup.

    "Why are you speaking to your shoulder?" I asked.

    "It's a radio," he said.

    "Looks like your shoulder," I said.

    The officer realised he didn't have his radio system equipped and this seemed to push him over the edge into a fury.

    "481.121. OFFENSE: POSSESSION OF MARIHUANA." he yelled. "You're NICKED!"

    "Nicked?" I said. "Nicked? You've been watching too much Inspector Morse," I helpfully suggested.

    "Don't play games with me you helpless little prat," he shouted. Definitely too much Inspector Morse.

    "Officer, this is not marihuana," I said calmly, peering into his deep brown eyes. "These are not the droids you're looking for!" I asserted, wiggling my fingers.

    "The labels on the packets clearly say they are!"

    "These are not the droids you're looking for."

    "I'm not looking for fc*@($ droids, I'm looking at your marihauana!"

    "Hodor", I said.

    "What?"

    "Hodor, hodor, hodor!"

    The officer looked at me as if I was some kind of maniac. "Look son, I think I'm going to have to arrest you for possession of all this marihuana."

    "It's not," I said.

    "Not what?"

    "Marihuana."

    He looked at me. "Blimey! Of course it is, it's even labelled!"

    "No, it's mariJuana."

    "Is that different?"

    "I believe so. It's got a different spelling at least."

    He looked at me cautiously. "Is this some kind of trick?" he asked, his eyes narrowing.

    "Of course not. It's all legit."

    Muttering he got a large book out of his top pocket. "Look 'ere, offence 481.121," he said pointing at the large tome. "It's quite clear."

    "That's for marihuana!" I said getting quite frustrated.

    His eyes glazed over and I watched his lips silently reading the words aloud. "Perhaps you're right," he reluctantly conceded.
    Last edited by Hodor; 01-29-2014 at 12:26 AM.

  11. #11
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Quote Originally Posted by Adak View Post
    1) Yes, there is. It isn't a "command", it's built into the logic of loops.

    2) Yes. If you'll post a couple more (they can be short) statutes not for marijuana, I'll make a short example of one way it could be done.

    You want the entire statute for that keyword, printed up, correct?
    Correct, if the Officer types in 481.121. The program would then bring up the statute. Here are a couple partial offense codes.

    HS. CODE ANN. § 481.115 : Texas Statutes - Section 481.115: OFFENSE: POSSESSION OF SUBSTANCE IN PENALTY GROUP 1
    b) An offense under Subsection (a) is a state jail felony if the amount of the controlled substance possessed is, by aggregate weight, including adulterants or dilutants, less than one gram.

    HS. CODE ANN. § 481.1151 : Texas Statutes - Section 481.1151: OFFENSE: POSSESSION OF SUBSTANCE IN PENALTY GROUP 1-A
    (b) An offense under this section is:

    (1) a state jail felony if the number of abuse units of the controlled substance is fewer than 20;
    Last edited by James Longoria; 01-29-2014 at 12:40 AM.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Do you want the search to be by statute number alone, or by the word MARIHUANA?

  13. #13
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Quote Originally Posted by Adak View Post
    Do you want the search to be by statute number alone, or by the word MARIHUANA?
    By the Offense statute number 481.121,481.115 etc.

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Something like this would be a start:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define OUT 0
    #define IN 1
    
    int search(void);
    
    int main() {
       int n=0;
         
       n=search();
       if(n>0)
          printf("\nTarget statute found\n");
       else
          printf("\nTarget statute not found\n");
    
    
       return 0;
    }
    int search(void) {
       int state=OUT,len=0;
       char end[]="HS. CODE ANN";
       char *found=NULL;
       char buff[120];
       char target[20];
    
       FILE *fp=fopen("Texas Statutes.txt","r");
       if(!fp) {
          perror("Error");
          return -1;
       }
       //printf("Enter the statute:     ");  //these three lines of code
       //fflush(stdout);
       //fgets(target, 20, stdin);           //are only REM'd out while debugging  
       strcpy(target, "481.115");            //remove when ready for testing other statutes
       len = strlen(target)-1;
       if(target[len]=='\n')
          target[len]='\0';
    
       while((fgets(buff, 120, fp)) != NULL) {
          found=strstr(buff, target);
          if(found) {
             state=IN;
             break;
          }
       }
       printf("\n");
       while(state==IN) {
          printf("%s\n",buff);
    
          fgets(buff, 120, fp);
          
          if(strstr(buff, end))
             state=OUT;
       }
    
       fclose(fp);
       
       if(found)
          return 1;
       else
          return 0;
    
    }
    You would want a more thorough test of the string that the user enters (the statute), etc.

  15. #15
    Registered User
    Join Date
    Jan 2014
    Posts
    13
    Quote Originally Posted by Adak View Post
    Something like this would be a start:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define OUT 0
    #define IN 1
    
    int search(void);
    
    int main() {
       int n=0;
         
       n=search();
       if(n>0)
          printf("\nTarget statute found\n");
       else
          printf("\nTarget statute not found\n");
    
    
       return 0;
    }
    int search(void) {
       int state=OUT,len=0;
       char end[]="HS. CODE ANN";
       char *found=NULL;
       char buff[120];
       char target[20];
    
       FILE *fp=fopen("Texas Statutes.txt","r");
       if(!fp) {
          perror("Error");
          return -1;
       }
       //printf("Enter the statute:     ");  //these three lines of code
       //fflush(stdout);
       //fgets(target, 20, stdin);           //are only REM'd out while debugging  
       strcpy(target, "481.115");            //remove when ready for testing other statutes
       len = strlen(target)-1;
       if(target[len]=='\n')
          target[len]='\0';
    
       while((fgets(buff, 120, fp)) != NULL) {
          found=strstr(buff, target);
          if(found) {
             state=IN;
             break;
          }
       }
       printf("\n");
       while(state==IN) {
          printf("%s\n",buff);
    
          fgets(buff, 120, fp);
          
          if(strstr(buff, end))
             state=OUT;
       }
    
       fclose(fp);
       
       if(found)
          return 1;
       else
          return 0;
    
    }
    You would want a more thorough test of the string that the user enters (the statute), etc.

    I removed line 36, it allows the program to freely search for the entered statute. The coding is way above my programming knowledge. I was able to recognize a couple lines of coding. The code works great, I just have to study all the lines of code for my personal knowledge. You have saved me so much time out in the field and have provided a great deal of knowledge thanks Adak!
    Last edited by James Longoria; 01-29-2014 at 08:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 05-05-2012, 09:36 PM
  2. TCP/IP sockect programming software
    By simona in forum Networking/Device Communication
    Replies: 4
    Last Post: 12-18-2011, 01:50 AM
  3. Replies: 9
    Last Post: 02-27-2006, 04:45 AM
  4. New Ms Programming Software!!!
    By sean in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-25-2002, 05:40 AM
  5. Software Testing to Programming
    By stratovarius519 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 02-23-2002, 01:05 PM