It is possible to read/write the binary of any file with using Python? `open(file, "b")` only works for windows `"rb"` `"rb+"` `"wb"` `"wb+"` `"ab"` `"ab+"` works but `.read()` just prints the file contents not its binary

Member Avatar
Member Avatar
+0 forum 10

I'm supposed to just read a file and display certain information. I wrote the file in notepad and have it in the correct folder for my project, but when it opens (it DOES open), it doesn't display anything. Ideas? #include <iostream> #include <fstream> using std::cout; using std::cin; using std::ifstream; int ReadData ( int ssn[], int wage[], int hours[], char status[] ); int main () { int ssn[11]; int wage[11]; int hours[11]; char status[11]; ReadData ( ssn, wage, hours, status ); return 0; } int ReadData ( int ssn[], int wage[], int hours[], char status[] ) { int num_records = 0; …

Member Avatar
Member Avatar
+0 forum 4

My code only outputs 0.00 when 'y' is entered. Clearly, I'm a beginner. #include <iostream> #include <iomanip> #include <string> const double ADULTFEE = 18.00, CHILDFEE = 7.50, TRAINFEE = 6.00, BIRDFEE = 5.00; using namespace std; int main () { char reply = ' '; double adultNum = 0, childNum = 0, guestAdult = 0, guestChild = 0, trainNum = 0, birdNum = 0; double totalFee = 0; cout << "Welcome to Jake's Fee Calculator" << endl; cout << "How many adults (age 14 or over) are in your party? "; cin >> adultNum; cout << "How many children (age …

Member Avatar
Member Avatar
+0 forum 3

Hello everyone, I am new at Java(android)-before I have little information about Java lang- and in particular socket programming -before I do not know nothing about socket client server programming-, previously I wanted to write simple chat program by using Threads and now I pass this step, two android emulators can talk each other, to success -just for test even I parse whether it is string or integer- that I use ObjectInputStream and ObjectOutputStream classes with writeObject(obj: MyClass) (in Client Thread class) and readObject() (in Server Thread class). MyClass -just for now I hope with your help- contains only string …

Member Avatar
Member Avatar
+0 forum 8

How to convert a plain text file into a **charsequence** object?

Member Avatar
Member Avatar
+0 forum 1

Hello do you know whats wrong with this code? #include <stdio.h> #include <allegro5\allegro5.h> #include <allegro5\allegro_primitives.h> #include <allegro5\allegro_image.h> int main() { al_init(); FILE* pFile; return 0; } If I compile it, it fails and output is: main.c 1>c:\users\beda\documents\visual studio 2010\projects\c allegro\c allegro\main.c(9): error C2143: syntax error : missing ';' before 'type' But if I run it as C++ code (source code is called main.cpp) it runs without problems. And I am using VC++ 2010. Thanks for help.

Member Avatar
Member Avatar
+0 forum 1

Write a java program that will open a file, read each of the records from the file, use that data to populate a two dimensional array and write the sorted data out to a new text file. Define a class named [B]Munge[/B] which will do all the 'heavy lifting' in this program. Build your project in NetBeans using the Run - Build Project, or Run - Clean and Build Project menu item. From the dist directory you will execute your program from the command line with two filenames as arguments, input file name and output file name. For example: [B]java …

Member Avatar
Member Avatar
+0 forum 4

I have the following piece of code. I do not understand why its not working. I'd really appreciate help on this. [CODE]import java.util.Scanner; import java.io.*; class ReadFiles { String [] codes = new String[99]; int i = 0; private Scanner readCodes; public void openCodesFile() { try { readCodes = new Scanner(new File("C:/Users/Carlo/Desktop/Files/codes.txt")); } catch (Exception e) { System.out.println("Could not locate the data file!"); } } public void readCodesFile() { while(readCodes.hasNext()) { codes[i] = readCodes.nextLine(); i++; System.out.println(codes[i]); } } public void closeCodesFile() { readCodes.close(); } } class NewHardware { public static void main(String[] args) { ReadFiles codesRead = new ReadFiles(); codesRead.openCodesFile(); …

Member Avatar
Member Avatar
+0 forum 1

What I'm trying to do is read a line from a file containing some data that includes a person's first and last name, their hourly wage and the number of hours they worked, and then writing to a seperate file their last name, first name: wage. The input file looks something like this: First Name 15.00 40.00 New Name 12.75 38.50 The output file should read something like this: Name, First: $600.00 Name, New: $490.86 Easy peasy, right? Everything seems to be in working order, except, that when it writes to the file, it writes it four times! [CODE]def fileInOut(): …

Member Avatar
Member Avatar
+0 forum 13

Whats up everyone I have a question, but first of all I know how to read a file, write to it and all that good stuff I was wondering how do I manipulate data from one. I want to take this .txt file and compute the gpa by taking the student grade and and number of hours the course is out of the file and doing the math for them. How would I go about doing this I'm kind of stumped. Here is the .txt file. A123456 John Doe Term Fall 2011 CS 411 Object Oriented Programming 3 A CS …

Member Avatar
Member Avatar
+0 forum 2

Hey guys I have this code snippet and I want to read from this file and print the contents of my text file (Transcript.txt) to the screen. I don't have any errors but when I run the program it prints "Display it to the standard output" instead of whats on my text file could I please have some assistance with this. [CODE] import java.io.File; import java.util.Scanner; public class GPAapp { public static void main(String[] args) { Scanner reader = null; try{ reader = new Scanner(new File("Transcript.txt")); } catch(Exception e){ System.out.println("File does not exist"); } while(reader.hasNext()){ System.out.print(reader.next()); } reader.close(); } } …

Member Avatar
Member Avatar
+0 forum 9

Task: • Create a text file with 5 questions in it. • Read each question in from the file. • Ask the user for their response. • Create a new text file. • Write the user’s answers to the text file. • Ask the user if they’d like to review their answers. If yes, read in their answers from the text file. If no, end the program. Here is my code... [CODE]# November 9, 2011 # A Few Questions print "Please answer these questions." print few_Questions = open("few_questions.txt","r") print few_Questions.readline() Ques1 = raw_input ("") print few_Questions.readline() Ques2 = raw_input ("") …

Member Avatar
Member Avatar
+0 forum 3

iam building a training set for spam filtering using java,training set data is given as words in text files in one folder,but im unable to debug whats going wrong in java collections [CODE]/* *folder part 1 conatins various text files having name format * **spmsg***.txt and ***legit***.txt e.g 11927legit569.txt ,106127spmsgc26 * inside it it has contents like Subject: 5581 2005 47 * 1791 80 15184 64 2155 5581 2005 80 21292 10607 47 64 * 209 22910 132 1672 84 3865 84 1570 84 2005 84 10492 1847 12330 4797 82 13886 2170 47 */ package naive_bayes; import java.util.*; import …

Member Avatar
Member Avatar
+0 forum 5

hello all i am doing a copy operation from a file to another file.in source file i have 13 digit no but in destination file there is only 12 digit copied.code is as follows. [CODE]public void createOriganalFile() { try { File ObjInputFile1 = new File(strFilepath + "_dummy.txt"); File ObjOutputFile1 = new File(strFilepath); String strLine1 = ""; BufferedReader ObjBufferReaderIn1 = new BufferedReader(new FileReader(ObjInputFile1)); BufferedWriter ObjBufferReaderOut1 = new BufferedWriter(new FileWriter(ObjOutputFile1)); do { if ((strLine1 = ObjBufferReaderIn1.readLine()) == null) { System.out.println("strLine1 is null"); break; } System.out.println("strLine--------- " + strLine1 +" strFilepath " + strFilepath); ObjBufferReaderOut1.write(strLine1,0,13); ObjBufferReaderOut1.newLine(); ObjBufferReaderOut1.flush(); System.out.println("Here After: "+strLine1);//13 digit no } …

Member Avatar
Member Avatar
+0 forum 2

HI, I am looking for faster input and output method for the C other than just normal scanf and printf modules. Please elaborate by simple example. thanks :)

Member Avatar
Member Avatar
+0 forum 8

[CODE] #include <iostream> #include <fstream> using namespace std; int main() { char ch; ofstream outf("ITEM.txt"); cout << "Enter item: "; char name[30]; cin >> name; outf << name << "\n"; cout << "Enter item cost: "; float cost; cin >> cost; outf << cost; cout << "written to file item.txt\n"; outf.close(); ifstream inf("ITEM.txt"); cout << "current location of pointer: " << inf.tellg() << endl; inf.seekg(0); while(!inf.eof()) { inf.get(ch); cout << ch; } cout << "\nreads from file item.txt"; inf.close(); cin.ignore(numeric_limits< streamsize >::max(),'\n'); cin.get(); return 0; } [/CODE] can you tell me why do i get a wrong output when I …

Member Avatar
Member Avatar
+0 forum 2

My professor has thrown me a curve ball with this next assignment. The assignment is to make a Monthly Accounting Statement, the program is to you structs and arrays. I get how you can have an array of structs, arrays within a struct, etc... I have the program mapped out accept for this one part. When I reading in the customer names from the customer.txt file, some of the names have a middle initial, and some dont: 631502 Legg T. 2839 Lionel Ave. +16.30 180003 Hofstra M. 225 Smith Str -6.00 000963 Malioneyh P. J. 4344 Nero Rd +366.92 517724 …

Member Avatar
Member Avatar
+0 forum 2

Hey guys. So I want to learn how to do a simple I/O to and from a file. I want the simplest way to do this. My teacher sent me her program but I don't think I get what she is doing and it's giving me an error. So I would also like to clarify a term - Tokenizer. Also, how do I read multiple lines? or find out how many lines are there in a file which are not blank? And if the input is separated by white space, how do I get each one into a separate variable? …

Member Avatar
Member Avatar
+0 forum 8

I thought this program was as good as done, turns out, it's more broken than I thought! Right now I'm in a panic, since it's due tomorrow, and I have a few big problems with it. Problem 1: I need to either open an existing file, or a new one depending on what the user wants. Opening an existing file works to a certain extent. If the user screws up and enters a bad file name, it says it can't find the file and prompts them if they want to try again, if they say yes, I'm screwed because even …

Member Avatar
Member Avatar
+0 forum 2

I am newbie in C programming and I have a easy assigment but I coul not do that. I need to read two number from a file, add them, print them that is all. Here is the my code. [CODE] #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp; fp = fopen("erogol.k","r"); char a =fgetc(fp); int aInt = atoi(&a); char b =fgetc(fp); int bInt = atoi(&b); printf("%d \n",bInt+aInt); return EXIT_SUCCESS; } [/CODE] My File has "9 4" and I need to take each number 9 and 4 them sum them but the program does not work. Can you help me?

Member Avatar
Member Avatar
+0 forum 7

Hi, I'm trying to make a program that reads a text file that contains about 4 rows of numbers and outputs the average for each row. I need help with these two errors. It is not complete but I need help on these so I can continue. Any help is appreciated. Thanks in advanced. Error 1 error C2109: subscript requires array or pointer type line 41 Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion) line 52 [CODE]#include <iostream> #include <fstream> #include <iomanip> using …

Member Avatar
Member Avatar
+0 forum 1

[CODE]import java.io.*;public class Ex9a{ public void rollBack(BufferedReader in) throws IOException{ String line=""; if((line=in.readLine())!=null){ rollBack(in); } if(line!=null&&!"".equals(line)){ System.out.println(line); } } public static void main(String[] args) throws FileNotFoundException{ PrintStream out; Ex9a t=new Ex9a(); out = new PrintStream(new FileOutputStream("outfile.txt")); out.println(ioe); out.close( ); String fileName="infile.txt"; try{ BufferedReader in=new BufferedReader(new FileReader(fileName)); t.rollBack(in); }catch(IOException ioe){ System.out.println(ioe); } } } [/CODE] infile is basically a bunch of lines of a poem and I need to reverse these lines and output them into an out file. The output file is created but it has nothing in it. Please help.

Member Avatar
Member Avatar
+0 forum 3

I can not figure out why my code is reading in data to my vector in funny ways. I have added the input file and necesary class to test. It seems to be skipping values in the input file and also adding things to seperate places in the vector instead of one place like I intended. Any help would be much appreciated. [code=java] import java.util.*; import java.io.*; public class AddressBook { public static Vector<Contact> contacts = new Vector<Contact>(100, 10); //buildBook creates Contacts from the input txt file and adds them to a //vector. This vector is our Address Book public …

Member Avatar
Member Avatar
+0 forum 1

hi, im trying to read and write an array of integer to/from a file. i use this to write to a file: [code=c]fwrite(texel, sizeof(int), size, fp);[/code] and this to write it: [code=c] (*out) = new int[size]; fread((*out), sizeof(int), size, fp); [/code] but the data read from the same file is different. im not sure what happened but from the real data, its a bunch of integer with differnece = 2 (even numbers) but when i read it, its a sequence of number(1, 2, 3, 4). i think its halved or something. any idea why? thanks in advance

Member Avatar
Member Avatar
+0 forum 1

I am trying to solve the problem Present at [url]http://www.codechef.com/problems/INTEST/[/url] I have made a small Python script to do my job :- [CODE]array = [] no_lines = 0 no = 0 j=0 div_no=0 no_lines = input() no = input() temp = no_lines while(no_lines>0) : i=0 i = input() array[j] = i j = j+1 no_lines = no_lines - 1 j=0 while(j<temp) : if array[j] % no == 0 : div_no=div_no+1 j = j+1 print(div_no,"\n")[/CODE] I am having a problem in Inputing 2 integers on the same line [CODE]no_lines = input() no = input()[/CODE] I am really confused...How to get a …

Member Avatar
Member Avatar
+0 forum 3

Well, I have a test program, in which I wanted to test if it was possible to open a textfile(text.txt) for input, display it via cout, then passing the object via reference to another function, in it and display the file again(which should already be open,which is the whole point). The thing is that, it does show it's open(via is_open()), but it doesnt display anything, inside the test() function, but it does inside the main() function. I would like for someone to help me make this program to display the input file inside the test() function. Here is the code …

Member Avatar
Member Avatar
+0 forum 1

Good day, everyone. I am refreshing my c++ skills from a year break or so :$ I am having some troubles remembering on how to write to a file. I have the general idea down, but I am not sure what I am doing wrong. I would be much appreciative if anyone can help me figure this out. (by the way I am using Netbeans IDE 6.8) Here is my code: (the red text is where the trouble is) [CODE]/* * Program to let user login and logout. * User's information will be put into a separate .txt file called …

Member Avatar
Member Avatar
+0 forum 10

hi all i have an assignment in which i have to use object-oriented programming to read from an input file(say: input.txt), use prim's algorithm and calculate the weight of a minimun spanning tree and then save the output to a file(output.txt). the problem with my code is that the program closes as soon as i compile and run it, however, the output is correctly printed and saved in the output file. can anyone please help me with this. this is the content of input.txt : [I]9 13 1 2 10 1 9 60 1 3 30 2 9 50 2 …

Member Avatar
Member Avatar
+0 forum 3

Hi, first let me stress - I have no real computer knowledge and most of the phrases etc mean nothing to me! I'm a stay at home mum and work from home making stationery etc and my husband bought me an external hard drive to back all my work up to (loads and loads of photos) as I lost everything TWICE through my computer dying on me. The computer is rubbish and has been from the day I got it (fijitsu siemens) It has had replacement memory boards, hard drives and basically been rebuilt more times than I care to …

Member Avatar
Member Avatar
+0 forum 2

hi I have been looking around for a good file io tutorial and I cant find any. It is simple enough to me the process, mov dx,043h mov al,54 out dx,al etc. but i have no idea which ports go to where or how to write to a hard disk or floppy drive etc. how do i find out which ports map to where?

Member Avatar
Member Avatar
+0 forum 6

The End.