565 Posted Topics

Member Avatar for padton

Well, you could try this: def sumFile(): sums = 0.0 files = ['a1.txt', 'a2.txt', 'a3.txt', 'a4.txt', 'a5.txt'] #here are your files for i in files: elems = (line.strip('\n') for line in open(i).readlines()) for j in elems: try: sums+=float(j) except ValueError as e: pass print sums sumFile()

Member Avatar for snippsat
0
225
Member Avatar for eric.i.perez

For your 1st part. This will tell you if a number is prime or not: bool isPrime(int nr){ if (nr == 0 || nr == 1) return false; for (int i=2;i<nr/2+1;i++) if (nr%i==0) return false; return true; } Now insert this validation into your loop, and see what you get. …

Member Avatar for NathanOliver
0
145
Member Avatar for rithish

Try this: #include <stdio.h> int main(void) { int ten = 10; int two = 2; printf("Doing it wrong: "); printf("%d minus %d is %d\n", ten ); // forgot 2 arguments printf("Doing it right: "); printf("%d minus %d is %d\n", ten, 2, ten - two ); return 0; } and see …

Member Avatar for Lucaci Andrew
0
136
Member Avatar for aVar++

Let me give you a head start: def myfunc(l): for i in range (1, len(l)-1): for j in range (1, len(l)-1): for define MyFunction (list): for OuterForLoopCounter in 1 to listlength-1: for InnerForLoopCounter in 1 to listlength-1: now, how about implementing the rest: if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]: swap …

Member Avatar for Lucaci Andrew
0
234
Member Avatar for sk8ergirl

Here, maybe this can help you: public void loadStudentsFromFile(){ BufferedReader in = null; try{ in = new BufferedReader(new FileReader(filename)); String line; while ((line = in.readLine()) != null){ String tokens[] = line.split(","); studs.add(new Student(Integer.parseInt(tokens[0]),tokens[1], Double.parseDouble(tokens[2]))); } } catch (IOException e){ System.out.println(e.getMessage()); } } where `studs` is: private ArrayList<Student> studs = new …

Member Avatar for tux4life
0
775
Member Avatar for raj REDDY

As **Adak** suggested, single digits followed by a comma (`','`) must be printed on their own line, pair of digits, separated by a dash (`'-'`) represents a sequence, where the 1st number is the lower bound, and the 2nd number is the upper bound, and you should print the whole …

Member Avatar for raj REDDY
0
201
Member Avatar for yup790

How about looping like this: int word_chooser = (int) (Math.random()*300); String word; LineNumberReader r = new LineNumberReader(new FileReader("words.txt")); while (r.getLineNumber()<word_chooser) r.readLine(); word = r.readLine(); System.out.println(word); It's rather impossible to read just a line from the middle of the file not knowing anything about it from advance. You'll have to read …

Member Avatar for stultuske
0
415
Member Avatar for dachy12

There's no need to have a function `input()` like this: void student::input(string name, int id, int grade1, int grade2, int grade3) { cout<<"enter student id number"<<endl; cin>>id; cout<<"enter student name"<<endl; cin>>name; cout<<"enter three grades"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; } when you have your private members like the function's arguments: string name; …

Member Avatar for dachy12
0
124
Member Avatar for ITech
Member Avatar for Lucaci Andrew
0
74
Member Avatar for jasonmark238

Have you even bother searching your answer on Google first? Maybe this liks can help you: [Click Here](http://docs.oracle.com/javase/tutorial/java/concepts/interface.html) [Click Here](http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html) An interface is a "pure" abstract class. It provides only a form, such as the method names, argument lists and the return types, but not the actual implementation, not the …

Member Avatar for stultuske
-1
214
Member Avatar for some

Well, it's not hard to figure that yourself, given the present code... DWORD WINAPI procOpen(std::string path){ LPSTR run=const_cast<char *>(path.c_str()); STARTUPINFO sInfo; PROCESS_INFORMATION pInfo; ZeroMemory(&sInfo, sizeof(sInfo)); sInfo.cb = sizeof(sInfo); ZeroMemory(&pInfo, sizeof(pInfo)); DWORD id; if (CreateProcess(NULL, run, NULL, NULL, false, 0, NULL, NULL, &sInfo, &pInfo)) { id = GetCurrentProcessId(); CloseHandle(pInfo.hProcess); } return …

Member Avatar for Lucaci Andrew
-1
226
Member Avatar for TheNotoriousWMB

As **gkbush** said, you first need to make sure that the strings have even length. Here's a simple function that might help you: void getEven(string &str1, string &str2){ if (str1.size()==str2.size()) return; else if (str1.size()<str2.size()) while (str1.size()!=str2.size()) str1.push_back('0'); else while (str2.size()!=str1.size()) str2.push_back('0'); } This will add `'0'`'es to the smaller string. …

Member Avatar for Lucaci Andrew
0
179
Member Avatar for arcticman452

> The code pName = &name should be either pName = name or pName = &name[0]. Actually `pName = &name[0];` isn't valid, because you try to convert `char*` to `string*`. Also `char* pColor = &color[10];` will do you no good, since `&color[10]` references some memory area that `color` itself doesn't …

Member Avatar for arcticman452
0
153
Member Avatar for erms

Well, you could put a `System.exit(0);` after you exit from the infinite loop... Say, for example, that you have a Thread class as mentioned above: new Thread(new Runnable(){ @SuppressWarnings("static-access") public void run(){ int i=0; while(stp){ captureScreenShot(".", "jpg", "pic"+Integer.toString(i++)+".jpg"); try { Thread.currentThread().sleep(2000); } catch (InterruptedException e) { //error handling if needed …

Member Avatar for erms
0
4K
Member Avatar for dendenny01

Well, to make it smaller, you could do like this: #include <stdio.h> #include <string.h> int main(){ FILE *f; char cho; char filename[] = "text .txt"; char text[] = "Your choice is .\n"; char* error,* errtxt; printf("Insert choice: "); scanf ("%c", &cho); switch(cho){ case '1': filename[4] = text[15] = cho; break; …

Member Avatar for dendenny01
0
458
Member Avatar for ndeniche

"Sir, do you know why we stopped you?" "No." "You, sir, were speeding." "Impossible."

Member Avatar for chrishea
0
1K
Member Avatar for jim.hurley

Making your `FIGURE_TYPE` struct from your `Figure` class public can solve your problem. Presumably your `FIGURE_TYPE` is in the defauls private block of your class, which means you can't access it directly. Making it public allows other classes to use that struct, even if it's declared in the `Figure` class. …

Member Avatar for jim.hurley
0
620
Member Avatar for fmkolawole
Re: life

Depends on the nature of your question: * life is the opposite of death. > what life is all about No one knows, every man defines his purposes, either by adopting some ideas, or by creating some. Life is that journey in which you strive to reach your goals...

Member Avatar for <M/>
0
81
Member Avatar for P3C1

> # Pointer to pointer to pointer to 2d array Why would you need that? Can you explain a bit? Because, if you want a 2d array you should do what **deceptikon** suggested; perhaps you want it for a reason, one that you haven't shared...

Member Avatar for P3C1
1
141
Member Avatar for lewashby

char *strNumber = argv[1]; it's different from the object : string strNumber = argv[1]; `char *strNumber` is an array of characters, whereas `string strNumber` is a `string` object. try this instead: #include <string> #include <iostream> using namespace std; int main(int argc, char* argv[]){ string nrString (argv[1]); nrString = '0' + …

Member Avatar for Moschops
0
154
Member Avatar for nitin1

> and if it is pointer, then why do you still need to use c_str() ? Array of charaters are considered (in C++) to be C style strings, where they would be just a sequence of characters in the memory. `string` on the other hand, is a C++ class that …

Member Avatar for Lucaci Andrew
0
211
Member Avatar for harinath_2007

Maybe this can come in handy: import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class view extends JFrame{ private JTextArea tx = new JTextArea(); private JScrollPane scroll = new JScrollPane(tx); public view(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tx.setEditable(false); JPanel but = new JPanel (new GridLayout(2, 2)); but.add(new …

Member Avatar for harinath_2007
0
102
Member Avatar for shanki himanshu

Maybe this link will help you: [Click Here](http://stackoverflow.com/a/7100565/1432385) You actually write bytes, and when trying to write an int, presumably your platform int is iterpreted as 4 bytes, you will have like this: byte[] int[][][][] //4*byte As you know from your assembly courses, a byte is represented on 8 bits …

Member Avatar for Tumlee
0
548
Member Avatar for london-G
Member Avatar for london-G
0
395
Member Avatar for elrond

Here's a hint of how you can compute this number: **8**^4 + **2**^4 + **0**^4 + **8**^4 = 8208. Split the number into its digits. Sum the digits acordingly than compare to the initial number. How to split a number to get its digits, well simple: int a = 1234; …

Member Avatar for elrond
0
261
Member Avatar for lewashby

Well, as **mike** and **Suzie** said, the remainder is the part that remains after dividing two numbers. It can take values from 0 to divisor-1 (the number by which it divides) in the usual integer division. If you want to have the fractionar part of the number, and check if …

Member Avatar for deceptikon
0
108
Member Avatar for Andyvonschweal

Depending on your version of Python: 2.x or 3.x this applies: 2.x: x = raw_input("Beeps: ") #gets the input as a string try: x=int(x) #tries to convert it to an int except Exception as e: print "Not an int." #if it fails an error message is shown 3.x: x = …

Member Avatar for Lucaci Andrew
0
253
Member Avatar for DeepAnalyzer

As **JamesCherrill** said, use the `append()` function to insert strings into your textArea. `setText()` sets the text area to whatever String you provide, much like opening a file in `"w"` or in `"a+"` mode. jTextArea2.setText("Item Name"+" | "+"Price"+" | "+"Item Number\n"); //clears the text area and inserts the header for(int …

Member Avatar for Lucaci Andrew
0
220
Member Avatar for ztdep

Till than, you can make use of what C++ already offers you: std::string to_string(double nr){ std::stringstream token; token<<nr; return token.str(); }

Member Avatar for tinstaafl
0
972
Member Avatar for on93

Your while is kinda wrong: while (cur !=NULL); Your code chrashes the program: do{ if( cur->st.id==id ) break; p = cur; cur = cur -> link; } while (cur !=NULL); //after it finishes the while p->link = cur->link; //link is undefined if cur = NULL. NULL doesn't have a "link"... …

Member Avatar for Lucaci Andrew
0
107
Member Avatar for triumphost

So exactly, what do you want? Do you want to > run a function every actual tick. or do you want to get the milliseconds?

Member Avatar for deceptikon
0
2K
Member Avatar for kchat

It's because `TrainA` is not in the scope of the insert function. `TrainA` is declared inside a for loop (line 166), which, after it's done, will free the variable, making it unknown to the whole function. Try to get it out of that for. Not to mention that this is …

Member Avatar for Lucaci Andrew
0
208
Member Avatar for on93

Deleting items from a linked list: 1: deleting the head. If you want to delete your head of the list you should do this: node temp set temp = head set head = head.next delete temp 2: deleting an item from the middle For deleting an item from the middle …

Member Avatar for on93
0
173
Member Avatar for erkanay

Well, depends on your merging. If you need only to concatenate the lists, than you should set your 1st list tail node to the head of your 2nd list(blink), and the tail of your 2nd list to the head of your 3rd list. To make it a circular list, set …

Member Avatar for erkanay
0
173
Member Avatar for on93

Try initializing head to something, say to `NULL` by calling `linklist_1()` 1st. Or better, initialize head to `NULL` in the constructor (which you don't have)... //class public: linklist(){head=NULL;} void linklist_1(); //no need; void linklist_2(); void insFirstNode (string name, int id, string prog, double cgpa); void printAllList(); //class stuff and you …

Member Avatar for Lucaci Andrew
0
128
Member Avatar for northrox

Yes, indeed. Line 20: cin>>m_name[count]; should be cin>>m_name; Also, it is ill-advised to use the `#include <conio.h>` header, because is a non-standard include, and is OS dependent (mainly Windows). You printing function is also wrong. For example, if I type in option 1, and I put there some string, for …

Member Avatar for Lucaci Andrew
0
216
Member Avatar for tinstaafl
Member Avatar for Dani
0
2K
Member Avatar for avidwan

In place reversal: char * str <- "something" char temp i <- 0 j <- strlen(str) - 1 while (i <= j) do temp = str[i] str[i++] = str[j] str[j--] = temp end_while On another `char*` char * str <- "something" char rev [strlen(str)] i <- 0 j <- strlen(str) …

Member Avatar for rustysynate
0
275
Member Avatar for Lardmeister

We're still here... Perhaps there were some buggs when they computed the end of the world date.

Member Avatar for sneekula
2
2K
Member Avatar for <M/>

If you're searching just for the editor, with no additional environment to your programming language, I would suggest Sublime Text 2 or Notepad++ (no direct support for *nix). If you do search for a complete IDE, than I suggest trying some IDE's, and settle for what suites you better.

Member Avatar for sneekula
0
211
Member Avatar for dureadan
Member Avatar for Lucaci Andrew
-2
204
Member Avatar for Feal456

**@Raisefamus** No need for a goto statement to simulate a loop, and [here](http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF) is the explanation. **@Feal456** You could use a while loop as mentioned before. You could use also a for loop: string Choice; for (;;){ cout<<"Choose: "; cin>>Choice; //if-else if conditions; else if (Choice == "6") break; else …

Member Avatar for CGSMCMLXXV
0
3K
Member Avatar for fheppell

Here, this might help you: try: with open (cardno+".txt", "r") as f: try: value = float(f.readline()) except ValueError as e: print "Empty card" if (value < total): print "Not enough money." else: value -= total with open (cardno+".txt", "w") as f: f.write(str(value)) except IOError as e: print "Invalid card"

Member Avatar for Lucaci Andrew
0
162
Member Avatar for Raisefamous

Well, code completion is good when you're dealing with a large application, and when you have lots of classes, with similar names/functions/members. Related to small applications, I do like to type everything, because: 1. when you need something, you have to go search it first in your brain, than in …

Member Avatar for tinstaafl
0
298
Member Avatar for Reverend Jim
Member Avatar for StefanRafa0

Here, this function will check if a string is a number or not: bool isNumber(string str){ bool doted=false; if (((int)str[0]<(int)'0' || (int)str[0]>(int) '9') && str[0]!='-') return false; for (size_t i=1;i<str.size();i++){ if (!doted && str[i]=='.') doted=true; else if (((int)str[i]<(int)'0' || (int)str[i]>(int) '9')) return false; } return true; } > and i …

Member Avatar for Lucaci Andrew
0
259
Member Avatar for communism

Well you could easily acomplish that by using some Linux C functions: send: [Click Here](http://linux.about.com/library/cmd/blcmdl2_send.htm) (also in your terminal man send) recv: [Click Here](http://linux.about.com/library/cmd/blcmdl2_recv.htm) (also in your terminal man recv) Here's a tutorial on that: [Click Here](http://beej.us/guide/bgipc/output/html/multipage/unixsock.html) Follow the steps Beej puts there, and you'll be fine.

Member Avatar for Lucaci Andrew
0
276
Member Avatar for pars99

Well, you could just simply return from that function: def f(): i=raw_input(": ") #i=input(": ") if (i=="1"): print "Hello!" #print ("Hello!") else: return

Member Avatar for vegaseat
0
279
Member Avatar for nullifyQQ

Well, I have to say: your code it's quite messy, and full of errors. class Class but yet you call the constructor as database(); You have this as private vector<string>database; yet you call void addString(vector<string> database,vector<string> newItem); with its own database `vector<string>` which will make this database.push_back(newItem[r]); locally, not actually …

Member Avatar for Lucaci Andrew
0
1K
Member Avatar for <M/>

The End.