I'm creating a program that carrys out certain things dependent on the user input. One function is to read text from a text file, another is to add text to the same text file. I'm unsure about how to add an exception handler to make sure the text input is in the right format, The text file contains a list of people with their birthdays in the form Mike,Dec,25 John,Apr,13 and I don't know what I would put around my code to add text, in order to not crash the program when text isn't entered in this format. Any help …

Member Avatar
Member Avatar
+0 forum 1

I am trying to catch error on file input/output. The try functions works fine but as it pass to the next line my code breaks. How can I exit gracefully when the 'infile' doesnt exist? [CODE] try: infile = open ('Book1.txt', "r") except IOError: print "input file %s is missing" %'Book1.txt' tex1 = infile.readline() outfile = open ('Book11.txt', "w") while tex1: rfields = tex1.split() # do something print >> outfile, 'something' outfile.close() infile.close()[/CODE] the error message I got: input file Book1.txt is missing Traceback (most recent call last): File "D:\pythonLearing\trial.py", line 11, in <module> tex1 = infile.readline() NameError: name 'infile' …

Member Avatar
Member Avatar
+0 forum 3

Hello again! I'm almost finished this project. However, the Clear button stopped doing its thing. It keeps giving me an "Invalid Cast Exception" whenever I am pressing the clear button. The project includes 2 forms--- JobInformation and Summary. The code follows: [CODE] 'Program Name: JobInformation 'Programmer: Zabinga 'Date: 11/28/2011 'Description: This program produces a summary of the amounts due for a bill for Pat's Auto Repair Shop. ' It incorporates menus, job information, a splash form, a summary form, and an About box form. 'Form: JobInformation Option Strict On Public Class JobInformation 'Declare projectwide variables. Public Shared JobNumberString As String …

Member Avatar
Member Avatar
+0 forum 21

I’m creating a program that displays random lines from a file. I have 8 lines on my text file and after displaying the last/8th random line… it displays [B][I]Segmentation fault[/I][/B] and then terminates the program. The program should display a message saying that there are no lines left to display. Can someone help me with this? Or can somebody tell me how to display the 8 lines only? This is the function I made so far… [CODE]int easy() { vector<string> text_file; string quest; char choice; int line_counter = 1; srand(time(NULL)); ifstream myfile ("./questions/easy.txt"); cout << "Welcome to EASY level category!\n" …

Member Avatar
Member Avatar
+0 forum 5

Can anyone help me with this? or alter the code of mine when it comes to the user Input here's the block of code of mine [CODE]public int Remove(int i, Briefcase c[], String[] m) { int nChoice = 0; System.out.print("\tPlease remove " + i + " cases: "); nChoice = input.nextInt(); if (c[nChoice] == null) { System.out.println(); System.out .println("\tYou already entered that digit choose again\n"); Remove(i, c, m); } else { System.out.println("\tI'm " + m[nChoice] + " You just removed case # " + nChoice); System.out.println("\t|" + nChoice + "| contains $" + c[nChoice].getAmount() + "\n"); } return nChoice; }[/CODE] …

Member Avatar
Member Avatar
+0 forum 29

The End.