Search Results

Search found 73 results on 3 pages for 'user69514'.

Page 3/3 | < Previous Page | 1 2 3 

  • Read multiple strings from a file C++

    - by user69514
    Hi I need to read different values stored in a file one by one. So I was thinking I can use ifstream to open the file, but since the file is set up in such a way that a line might contain three numbers, and the other line one number or two numbers I'm not sure how to read each number one by one. I was thinking of using stringstream but I'm not sure if that would work. The file is a format like this. 52500.00 64029.50 56000.00 65500.00 53780.00 77300.00 44000.50 80100.20 90000.00 41000.00 60500.50 72000.00 I need to read each number and store it in a vector. What is the best way to accomplish this? Reading one number at a time even though each line contains a different amount of numbers?

    Read the article

  • C Programming. How to deep copy a struct?

    - by user69514
    I have the following two structs where "child struct" has a "rusage struct" as an element. Then I create two structs of type "child" let's call them childA and childB How do I copy just the rusage struct from childA to childB? typedef struct{ int numb; char *name; pid_t pid; long userT; long systemT; struct rusage usage; }child; typedef struct{ struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ }rusage; I did the following, but I guess it copies the memory location, because if I changed the value of usage in childA, it also changes in childB. memcpy(&childA,&childB, sizeof(rusage)); I know that gives childB all the values from childA. I have already taken care of the others fields in childB, I just need to be able to copy the rusage struct called usage that resides in the "child" struct.

    Read the article

  • Why does this C++ code result in a segmentation fault?

    - by user69514
    I keep getting a segmentation fault when the readAuthor() method is called. Does anybody know why this happens? I am supposed to use dynamic arrays, I know this would be so easy if I was using static array. #include <iostream> #include <string> #include <cstring> #include <cstdlib> using namespace std; /** declare arrays **/ int* isbnArr = new int[25]; char* authorArr = new char[25]; char* publisherArr = new char[25]; char* titleArr = new char[25]; int* editionArr = new int[25]; int* yearArr = new int[25]; int* pagesArr = new int[25]; float* retailPriceArr = new float[25]; float* discountedPriceArr = new float[25]; int* stockArr = new int[25]; /** function prototypes **/ int readIsbn(); char* readAuthor(); char* readPublisher(); char* readTitle(); int readEdition(); int readYear(); int readPages(); float readMsrp(); float readDiscountedPrice(); int readStockAmount(); void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory); int main() { bool stop = false; //flag when to stop loop int ind = 0; //index for current book while( !stop ){ cout << "Add book: press A: "; cout << "another thing here "; char choice; cin >> choice; if( choice == 'a' || choice == 'A' ){ readonebook(&isbnArr[ind], &authorArr[ind], &titleArr[ind], &publisherArr[ind], &editionArr[ind], &yearArr[ind], &pagesArr[ind], &retailPriceArr[ind], &discountedPriceArr[ind], &stockArr[ind]); test(&authorArr[ind]); ind++; } } return 0; } /** define functions **/ int readIsbn(){ int isbn; cout << "ISBN: "; cin >> isbn; return isbn; } char* readAuthor(){ char* author; cout << "Author: "; cin >> author; return author; } char* readPublisher(){ char* publisher = NULL; cout << "Publisher: "; cin >> publisher; return publisher; } char* readTitle(){ char* title = NULL; cout << "Title: "; cin >> title; return title; } int readEdition(){ int edition; cout << "Edition: "; cin >> edition; return edition; } int readYear(){ int year; cout << "Year: "; cin >> year; return year; } int readPages(){ int pages; cout << "Pages: "; cin >> pages; return pages; } float readMsrp(){ float price; cout << "Retail Price: "; cin >> price; return price; } float readDiscountedPrice(){ float price; cout << "Discounted Price: "; cin >> price; return price; } int readStockAmount(){ int amount; cout << "Stock Amount: "; cin >> amount; return amount; } void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory){ *isbn = readIsbn(); author = readAuthor(); title = readTitle(); publisher = readPublisher(); *edition = readEdition(); *year = readYear(); *pages = readPages(); *msrp = readMsrp(); *discounted = readDiscountedPrice(); *inventory = readStockAmount(); }

    Read the article

  • java phone number validation....

    - by user69514
    Here is my problem: Create a constructor for a telephone number given a string in the form xxx-xxx-xxxx or xxx-xxxx for a local number. Throw an exception if the format is not valid. So I was thinking to validate it using a regular expression, but I don't know if I'm doing it correctly. Also what kind of exception would I have to throw? Do I need to create my own exception? public TelephoneNumber(String aString){ if(isPhoneNumberValid(aString)==true){ StringTokenizer tokens = new StringTokenizer("-"); if(tokens.countTokens()==3){ areaCode = Integer.parseInt(tokens.nextToken()); exchangeCode = Integer.parseInt(tokens.nextToken()); number = Integer.parseInt(tokens.nextToken()); } else if(tokens.countTokens()==2){ exchangeCode = Integer.parseInt(tokens.nextToken()); number = Integer.parseInt(tokens.nextToken()); } else{ //throw an excemption here } } } public static boolean isPhoneNumberValid(String phoneNumber){ boolean isValid = false; //Initialize reg ex for phone number. String expression = "(\\d{3})(\\[-])(\\d{4})$"; CharSequence inputStr = phoneNumber; Pattern pattern = Pattern.compile(expression); Matcher matcher = pattern.matcher(inputStr); if(matcher.matches()){ isValid = true; } return isValid; } Hi sorry, yes this is homework. For this assignments the only valid format are xxx-xxx-xxxx and xxx-xxxx, all other formats (xxx)xxx-xxxx or xxxxxxxxxx are invalid in this case. I would like to know if my regular expression is correct

    Read the article

  • C++ print value of a pointer

    - by user69514
    I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value? cout << arr[i] ? cout << &arr[i] ? they both print the address Does anyone know?

    Read the article

  • Java File manipulation

    - by user69514
    So I have an application with a JFileChooser from which I select a file to read. Then I change some words and write a new file. The problem that I am having is that when I write the new file it's saved in the project directory. How do I save it in the same directory as the file that I chose using the JFileChooser. Note: I don't want to use the JFileChooser to choose the location. I just need to save the file in the same directory as the original file that I read.

    Read the article

  • C++ problem with string stream istringstream

    - by user69514
    I am reading a file in the following format 1001 16000 300 12.50 2002 24000 360 10.50 3003 30000 300 9.50 where the items are: loan id, principal, months, interest rate. I'm not sure what it is that I am doing wrong with my input string stream, but I am not reading the values correctly because only the loan id is read correctly. Everything else is zero. Sorry this is a homework, but I just wanted to know if you could help me identify my error. if( inputstream.is_open() ){ /** print the results **/ cout << fixed << showpoint << setprecision(2); cout << "ID " << "\tPrincipal" << "\tDuration" << "\tInterest" << "\tPayment" <<"\tTotal Payment" << endl; cout << "---------------------------------------------------------------------------------------------" << endl; /** assign line read while we haven't reached end of file **/ string line; istringstream instream; while( inputstream >> line ){ instream.clear(); instream.str(line); /** assing values **/ instream >> loanid >> principal >> duration >> interest; /** compute monthly payment **/ double ratem = interest / 1200.0; double expm = (1.0 + ratem); payment = (ratem * pow(expm, duration) * principal) / (pow(expm, duration) - 1.0); /** computer total payment **/ totalPayment = payment * duration; /** print out calculations **/ cout << loanid << "\t$" << principal <<"\t" << duration << "mo" << "\t" << interest << "\t$" << payment << "\t$" << totalPayment << endl; } }

    Read the article

  • Open source project. I want to participate in something

    - by user69514
    I am a senior in Computer Science. I want to be part of some open source project. I don't know what's available out there. Can anybody guide me? I'm good with Java, not that great with C and C++, but I know both. I also know some Cincom Smalltalk. Or if anyone has something good that they're working on I could help.

    Read the article

  • Array of Structs Initialization....

    - by user69514
    Hi I am working on a program where I have to initialize a deck of cards. I am using a struct to represent a card. However I'm not filling it correctly as I get a bunch of zero's when I display the deck of cards. I believe my mistake is in this line but I'm not sure: struct card temp = {"Clubs", value, false}; The code: void initCards(){ int count = 0; int location = 0; const int hand = 12; //add hearts int value=2; while( count < hand ){ struct card temp = {"Hearts", value, false}; cards[location] = temp; value++; count++; } count = 0; //add diamonts value = 2; while( count < hand ){ struct card temp = {"Diamonds", value, false}; cards[count] = temp; value++; count++; } //add spades count = 0; value = 2; while( count < hand ){ struct card temp = {"Spades", value, false}; cards[count] = temp; value++; count++; } //add clubs count = 0; value = 2; while( count < hand ){ struct card temp = {"Clubs", value, false}; cards[count] = temp; value++; count++; } //print the deck for(int i=0; i<52; i++){ cout << cards[i].type << " " << cards[i].rank << endl; } }

    Read the article

  • C++ cin problems. not capturing input from user

    - by user69514
    I have the following method which is not capturing anything from the user.If I input New Band for the artist name, it only captures "New" and it lefts out "Band". If I use cin.getline() instead nothing is captured. Any ideas how to fix this? char* artist = new char [256]; char * getArtist() { cout << "Enter Artist of CD: " << endl; cin >> artist; cin.ignore(1000, '\n'); cout << "artist is " << artist << endl; return artist; }

    Read the article

  • Linked List Inserting strings in alphabetical order

    - by user69514
    I have a linked list where each node contains a string and a count. my insert method needs to inset a new node in alphabetical order based on the string. if there is a node with the same string, then i increment the count. the problem is that my method is not inserting in alphabetical order public Node findIsertionPoint(Node head, Node node){ if( head == null) return null; Node curr = head; while( curr != null){ if( curr.getValue().compareTo(node.getValue()) == 0) return curr; else if( curr.getNext() == null || curr.getNext().getValue().compareTo(node.getValue()) > 0) return curr; else curr = curr.getNext(); } return null; } public void insert(Node node){ Node newNode = node; Node insertPoint = this.findIsertionPoint(this.head, node); if( insertPoint == null) this.head = newNode; else{ if( insertPoint.getValue().compareTo(node.getValue()) == 0) insertPoint.getItem().incrementCount(); else{ newNode.setNext(insertPoint.getNext()); insertPoint.setNext(newNode); } } count++; }

    Read the article

  • Java reading files......

    - by user69514
    Ok this is a homework questions, but I cannot find the answer anywhere, not even in the book. Path to Files If the user wants to specify a path for a file, the typical forward slash is replaced by ________. can you help?

    Read the article

  • Create servlet from existing Java project

    - by user69514
    I have a Java Swing project for my class. I would like put it on my website so people can use it. However I'm not sure if there is a way to turn it into a servlet. Or do I need to know JavaScript? I'm confused. Is there a way to make my swing application into a servlet automatically?

    Read the article

  • Linked List. Insert integers in order

    - by user69514
    I have a linked list of integers. When I insert a new Node I need to insert it not at the end, but in oder... i.e. 2, 4, 5, 8, 11, 12, 33, 55, 58, 102, etc. I don't think I am inserting it in the correct position. Do see what Im doing wrong? Node newNode = new Node(someInt); Node current = head; for(int i=0; i<count; i++){ if(current == tail && tail.data < someInt){ tail.next = newNode; } if(current.data < someInt && current.next.data >= someInt){ newNode.next = current.next; current.next = newNode; } }

    Read the article

  • C++ sort array of strings

    - by user69514
    I am trying to sort an array of strings, but it's not sorting anything.... what am I doing wrong? string namesS[MAX_NAMES]; int compare (const void * a, const void * b){ return ( *(char*)a - *(char*)b ); } void sortNames(){ qsort(namesS, MAX_NAMES, sizeof(string), compare); }

    Read the article

  • Segmentation fault C++ in recursive function

    - by user69514
    Why do I get a segmentation fault in my recursive function. It happens every time i call it when a value greater than 4 as a parameter #include <iostream> #include <limits> using namespace std; int printSeries(int n){ if(n==1){ return 1; } else if( n==2){ return 2; } else if( n==3){ return 3; } else if( n==4){ return printSeries(1) + printSeries(2) + printSeries(3); } else{ return printSeries(n-3) + printSeries((n-2) + printSeries(n-1)); } } int main(){ //double infinity = numeric_limits<double>::max(); for(int i=1; i<=10; i++){ cout << printSeries(i) << endl; } return 0; }

    Read the article

  • C++ sort array of char pointes

    - by user69514
    Can you tell me what's wrong with my method? I ends up putting the same thing everywhre and it's actually not sorting. void sortArrays(){ int i, j; for(i=0; i<counter; i++){ for( j=0; j<i; j++){ if( strcmp(title_arr[i], title_arr[j]) < 0){ char* title_temp = title_arr[i]; title_arr[j] = title_temp; } } }

    Read the article

  • C++ stringstream reads all zero's

    - by user69514
    I have a file which contains three integers per line. When I read the line I use a stringstream to separate the values, but it only reads the first value as it is. The other two are read as zero's. ifstream inputstream(filename.c_str()); if( inputstream.is_open() ){ string line; stringstream ss; while( getline(inputstream, line) ){ //check line and extract elements int id; double income; int members; ss.clear(); ss.str(line); ss >> id >> income >> members; In the case above, id is extracted correctly, but income, and members get assigned zero instead of the actual value.

    Read the article

  • Java print binary number using bit-wise operator

    - by user69514
    Hi I am creating a method that will take a number and print it along with its binary representation. The problems is that my method prints all 0's for any positive number, and all 1's for any negative number private static void display( int number ){ System.out.print(number + "\t"); int mask = 1 << 31; for(int i=1; i<=32; i++) { if( (mask & number) != 0 ) System.out.print(1); else System.out.print(0); if( (i % 4) == 0 ) System.out.print(" "); } }

    Read the article

  • C++ sort array of char pointers

    - by user69514
    Can you tell me what's wrong with my method? I ends up putting the same thing everywhre and it's actually not sorting. void sortArrays(){ int i, j; for(i=0; i<counter; i++){ for( j=0; j<i; j++){ if( strcmp(title_arr[i], title_arr[j]) < 0){ char* title_temp = title_arr[i]; title_arr[j] = title_temp; } } }

    Read the article

< Previous Page | 1 2 3