Jump to content

danieldrave

Members
  • Posts

    17
  • Joined

  • Last visited

Profile Information

  • Favorite Area of Science
    Computer Science

danieldrave's Achievements

Quark

Quark (2/13)

0

Reputation

  1. Hey all, Our lecturers have provided us with an assignment where they want us to read in a file they've supplied in a certain file path. They want to be able to type in the file path through a standard input function. I have set the code up but whenever I run my code the program prints out the prompt for input but then skips to the next printf() statement. Here's the code: location *nav_information; ship *ship_information; /*instance of the struct in 'resources.h'* pointer needed for dynamically sized array */ time_format *times; FILE *fp; fp = fopen("LOGFILE.TXT", "w+"); /*this is the logfile we will write ship information and collision information in */ int duration; int time_gap; printf("Welcome to the Shipping Lanes NavBot!\n"); printf("Please enter the data file you wish to use...\n"); fscanf(fp, "%d %d %d %d %d %d", &times->days, &times->months, &times->years, &times->hours, &times->mins, &times->secs); while(!EOF) { fscanf(fp, "%c %f %f %d %d",&ship_information->AISID, &nav_information->lat, &nav_information->lng, &ship_information->course_over_groud, &ship_information ->speed); } printf("Please enter a duration for the simulation...\n"); On runtime the printf() message is printed out but I am unable to provide input as it skips to the next printf() function. N.B. I am also getting a warning which says 'statement not reachable relating to the fscanf() statement within the while loop. Can anyone provide a solution? Daniel
  2. Hi Guys, I'm trying to code some PHP in which a user selects a product by selecting a checkbox and then when they click on 'Add To Basket' it takes them to a shopping basket displays what they selected. Here's the code: <div id="main"> <form action="basket.php" autocomplete="off" name="formSubmit" method="post"> <div id="table"> <?php $conn = pg_connect("host=db.dcs.aber.ac.uk port=5432 dbname=teaching user=csguest pass word=*****"); $res = pg_query ($conn, "select * from CSGames order by refnumber"); <!-- TABLE HEADERS OMITTED --> while ($a = pg_fetch_array($res)) { echo "<tr>\n"; echo "<td><input type='checkbox' name='selection[]' value='$refnumber' /></td>"; for ($j = 0; $j < pg_num_fields($res); $j++) { echo "<td>\n" . $a[$j] . "</td>\n"; } echo "</tr>"; } echo "</table>\n\n"; echo "<input type='submit' name='send' value='Add to Basket' />"; ?> And the code for the 'shopping basket' page: <?php foreach($_POST['selection'] as $refnumber) { echo "Game:" .$refnumber. "<br />"; } ?> At the moment this is the only output I get... - 'Game:' - nothing afterwards... I believe the problem relates to how I'm referencing the variable 'refnumber' but I'm not sure how to resolve this. Thanks for the help guys, Dan
  3. I'm getting a null pointer exception at the line with Object o on it :/ However I think it may be an error in my main method.. here's the source code but I'm not sure because all I'm doing is calling a method from the HashTable class & I have initialised that at the first line of the method. package cs21120_assignment_data; import java.io.*; import java.util.Hashtable; import java.util.Scanner; import javax.swing.SwingUtilities; public class Concordance { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { HashTable hashtable = new HashTable (); hashtable.addBook("oliver.txt"); hashtable.readSourceFile("index.txt"); } } The source code for the HashTable is the same as above, but I'm not convinced it's a problem with main method even after reading the error message... Exception in thread "main" java.lang.NullPointerException at cs21120_assignment_data.HashTable.addBook(HashTable.java:86) at cs21120_assignment_data.Concordance.main(Concordance.java:26)
  4. Thanks very much that really did help solve my problem! Marvellous xxx
  5. Java Assignment is really killing me!

    1. VisionIncision

      VisionIncision

      What does it entail?

  6. Hi all, Involved in many projects at the moment & I've had a mental block with this algorithm. Here's the source code, I'm trying to compare the keys in my Hashtable and the values in the array and if the "words" appear in both data structures to produce a result, but the line for line algorithm is really messing with my head: public void addBook(String filename) throws IOException { String[] linearray; String line; try { File b = new File(filename); BufferedReader fileread = new BufferedReader(new FileReader(b)); in = new Scanner(b); while(in.hasNextLine()) { line = fileread.readLine(); /* Read in whatever line */ linearray = line.split("([.,!?:;'\"-]|\\s)+)"); /* this handles punctuation and whitespace and adds it to the array */ for(int i=0; i<=linearray.length; i++) { } } } catch (FileNotFoundException e) { e.printStackTrace(); } } Any help you could provide would be great, I'm not looking for spoon fed source code, just some algorithms to help get my creative juices flowing! Dan xx
  7. Its fine I understand just getting a bit frustrated with my code, thanks for the link!
  8. Switched the code to your recommended source code: - The method keyset() is undefined for the type Hashtable<String,Object> That's the error message I'm getting! Is keyset() linked to HashTables or HashMaps because I'm not allowed to use HashMaps =]
  9. I changed it to public class Hashtable1 and the output still hasn't changed :/
  10. Hi Guys, I'm having a problem with the results I'm getting from my Hashtable code! It basically only prints out the last key and value I create in the fileSave() method. Here's source code: import java.util.*; import java.io.*; /** * HashTable Class * @author Daniel Drave * Version 1.0 */ public class HashTable { /* fileSave & fileLoad METHODS TO GO HERE, * THE TWO METHODS WILL HANDLE THE LOADING & SAVING OF THE SAMPLE .TXT FILE * IT WILL THEN BE LINKED TO THE A METHOD IN THE MAIN METHOD WHICH WILL COMPARE AND MATCH * WORDS FROM THE .TXT FILE TO THE OLIVER TWIST SAMPLE TEXT AND DISPLAY THE LINE NUMBERS * WHERE THE WORDS ARE IN OLIVER TWIST */ private static void fileSave() { /* WE MAKE A NEW HASHTABLE */ Hashtable <String, Object> hashtable = new Hashtable<String, Object>(); /* NOW WE'LL PUT IN SOME SAMPLE STRINGS */ hashtable.put("string", "tomorrow"); hashtable.put("string", "food"); hashtable.put("string", "coat"); hashtable.put("string", "outside"); /* WE'LL NOW USE A LARGE TRY & CATCH MEHTOD TO WRITE THE FILE TO OUR PROGRAM */ try{ System.out.println("Attempting creation of File Output Stream..."); FileOutputStream fileOut = new FileOutputStream("SampleText.txt"); ObjectOutputStream out = new ObjectOutputStream (fileOut); System.out.println("Attempting to write Hashtable Object..."); out.writeObject(hashtable); /* HASHTABLE RELATING TO THE ONE WE CREATED EARLIER */ System.out.println("Now closing all Output Streams..."); out.close(); fileOut.close(); } /* THROW IN SOME EXCEPTIONS IN CASE THE .TXT IS NOT FOUND */ catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } private static void fileLoad() { /* WE SET THE HASHTABLE TO NULL AS WE'RE GOING TO APPLY SOME KEYS & VALUES TO IT LATER */ Hashtable<String, Object> hashtable = null; try { System.out.println("Creating File/Object Stream..."); FileInputStream fileIn = new FileInputStream("SampleText.txt"); ObjectInputStream in = new ObjectInputStream(fileIn); System.out.println("Loading File/Object Stream..."); hashtable = (Hashtable<String, Object>)in.readObject(); System.out.println("Attempting to close Stream..."); in.close(); fileIn.close(); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } System.out.println("Printing out loaded elements..."); for(Enumeration<String> e = hashtable.keys(); e.hasMoreElements(){ Object obj = e.nextElement(); System.out.println("- Element(" + obj + ") = " + hashtable.get(obj) + "\n"); } } public static void main(String args[]) throws IllegalArgumentException { fileSave(); fileLoad(); } } And the result:... Attempting creation of File Output Stream...Attempting to write Hashtable Object... Now closing all Output Streams... Creating File/Object Stream... Loading File/Object Stream... Attempting to close Stream... Printing out loaded elements... - Element(string) = outside Any help you could provide would be great! Thanks Guys, Dan
  11. Hi all, I use ssh quite a lot at the command line/terminal (MAC OSX) to connect to my university server. The question is: what is the syntax for transferring directories from my home folders to the university server? Thanks, Dan xx
  12. Hi guys, got a small issue. I'm developing a site and I'm using the 960 Grid System, which is great everything should mathematically be alligned. I've got this problem as you can see above the social networking bar extends outside of the grid system. I've increased the padding on the links as a test just to see if was the links but it seems to be the division/div itself. Here's some source code, HTML: <div id="secondnavbar" class="grid_12"> <!--AS YOU CAN SEE ITS SET AT grid_12 SO I'M STUMPED--> <p class="navpar"> Social Media: <a href="http://www.facebook.com/aberguild" class="facebook"> FACEBOOK </a> <a href="http://twitter.com/#!/aberguild" class="twitter"> TWITTER </a> </p> <p class="navpar2"> Student Media: <a href="http://www.bay-radio.co.uk" class="bayradio">BAY RADIO </a> <a href="http://abercourier.com/" class="courier">THE COURIER </a> <a href="http://www.abertv.co.uk/" class="abertv">ABERTV</a> </p> </div> <!--end of secondnavbar--> CSS: .navpar, .navpar2 { display: inline; } .navpar2 { margin-left: 4em; } #secondnavbar { background-color: black; color: white; text-transform: uppercase; padding: 1em; padding-left: 0em; margin-top: 0em; margin-bottom: 1em; font-family: arial; font-size: 16px; font-weight: bold; } I really can't see any issue, so I thought a fresh programmer looking at it for the first time might spot the problem, its really just taken me back and is ruining my productivity! Thanks for the help, Dan
  13. Okay thank you for all your help if i can't solve it myself will upload to a server and inform you on here! xx
  14. hmm doesn't seem to appear on the side of the div. Here's the source the code... CSS: .twitterfeed { height: 30%; margin-bottom: 1em; background-image: url('img/twitter.png'); background-repeat: no-repeat; background-position: left top; margin-right: 200px; margin-left: 200px; } HTML: <div class="grid_4 twitterfeed"> <!--<p class="tbannertext"> Twitter Feed </p>--> <p> SAMPLE TEXT <BR> SAMPLE TEXT<BR> </p> </div> <!--END TWITTERFEED BOX-->
  15. tried out the code editor which is good with an image, could that be applied to text within a div as well? The image has no URL its a printscreen taken from a concept design that's part of a web project i'm working on.
×
×
  • 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.