C++ :: Program Producing Infinite Garbage?
May 1, 2013
Code:
// Lab0Inventory.cpp : Starter lab
//Anastasia Glyantseva
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
[Code]....
I can't figure out why my makeString gets called first and the pString its called with contains garbage. I want my allocateMem to get called first, but my program is not going to that. What is wrong with the order of my code?
View 3 Replies
ADVERTISEMENT
Sep 3, 2014
My program works fine in all areas but adding the average every loop. It gives me a weird -1.#IND as an output, and it's supposed to calculate the total mileage each time I enter new values per trip.
// Automobile Mileage.cpp : Defines the entry point for the console application.
//
//Programmer: Ryan Youngen
[Code].....
View 1 Replies
View Related
Jan 17, 2012
I have done some programming or rather have written and implemented some algorithms in code (is there a difference? :-)) but am having some teething problems with a project I am currently working on.
To start with I am simply reading in the data from a .txt file into a vector. This is the code that I currently have:
Code:
#include <iostream>
#include <fstream>
#include <cerrno>
#include <vector>
[Code]....
This compiles fine but currently outputs a different integer everytime I run the program. I can remember having this problem when I started coding before using a different language and if I remember correctly it was quite easy to resolve. I thought it was because I had missed off the 'return 0' but it is something similar I think.
View 3 Replies
View Related
Mar 22, 2013
The program works, other than if I place the cursor below the last line in my merch file, the program outputs a line of garbage. The only solution I could find is to leave the cursor on the last line.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct vRecord {
string venue, item;
float price;
[Code]...
View 2 Replies
View Related
Feb 10, 2015
So I learned how to make a basic for loop and I decided to try my best to make an infinite one. Every time I run it, it doesn't say anything and just closes. Visual Studio doesn't say there's anything wrong with my code.
Here's the code
#include <iostream>
#include <conio.h>
using namespace std;
int main () {
int d = 9;
for(int k = 10; k < d; k = k +1) {
cout << "For loop value = " << k << endl;
getch();
} }
View 4 Replies
View Related
Feb 14, 2014
I am getting an infinite loop when my program generates a new bracket
#include <iostream>
#include <string>
#include <stdlib.h>
#include <numeric>
#include <fstream>
#include <vector>
using namespace std;
const int MAXTEAMS = 20;
const char* c;
[Code] ....
View 2 Replies
View Related
Mar 18, 2014
I'm having trouble getting my loop to work correctly. If I iterate the for loop once it works as expected and displays proper output. When I try to iterate two times or more the program gets stuck in an infinite loop.
testData8.dat:
Code:
12 9
13 756
View 3 Replies
View Related
Feb 9, 2013
I have an assignment where i have to make a palindrome program. As you can see i have already done the basic palindrome prog, however i am now stuck since the program goes into a infinite loop whenever a word with whitespaces is added.
I have also tried searching for methods online however they do not seem to work for me...
void CPali::check() {
length = strlen(palin);
for (int i = 0, p = length-1; p>i; i++, p--) {
if (palin[i] == ' ')
[Code] ....
View 6 Replies
View Related
Jul 14, 2014
Why my calculate function is producing a zero?I feel like it may have something to do with there being zeros the arrays it takes. The arbitrary cout statements are just for my debugging purposes. Input is formatted as follows:
<int>
<int>
<string>,<int>,<int>
<string>,<int>,<int>
<string>,<int>,<int>
<string>,<int>,<int>
and so on
#include <iostream>
#include <string>
#include <sstream>
int** parse_input(int &num_items, int &pouch_size);
int* calculate(int &num_items, int &pouch_size, int *values, int *weights, int &max_value);
[Code] ....
View 1 Replies
View Related
Nov 14, 2014
Something is wrong with option 1. For some reason it adds 1, 2, 3, 4 ... 5 onto the output and I can't think why. Here is a screenshot.
Also how can I make the output a little neater? I tried to use but it just looks horrible.
I had linked the source code! Why is there no edit button?!
#include<iostream>
using namespace std;
int main(){
int option;
cout << "Welcome to my program. Please select a following option.
[Code] .....
View 3 Replies
View Related
Feb 2, 2014
when you enter a name between 'p' and 's' it should send you to room 2432 but no matter what value you enter it says you can get your tickets here.
Code:
#include <stdio.h>
main()
{
[Code].....
View 2 Replies
View Related
Sep 25, 2014
In my program I am supposed to call isEqualTo with a user defined class type, and print out if my two numbers being compared are equal or not. I had to write two versions of this, one with just a template which works fine, but when I implemented the class, all the sudden my program just spews out true no matter if actually equal or not. Here is what I have so far:
#include "stdafx.h"
#include <iostream>
#include "UserClass.h"
using namespace std;
template<typename T>
bool isEqualTo(T value1, T value2){
if (value1 == value2)
[Code] ....
View 4 Replies
View Related
Oct 27, 2013
I am working on a project and decided to try something simple before I start adding items. I am calling a function from main and that function has a file pointer.
Here is my main.cpp
Code: #include <cstdio>
#include <string>
#include <iostream>
#include "main.h"
extern FILE *fp;
using namespace std;
int main(int argc, char *argv[])
[code]....
Here is the function:
Code:
#include <string>
#include <cstdio>
#include <iostream>
#include "main.h"
[Code] ....
My test file consists of several characters and digits. Nothing special and I at this point in time do not have any type of formatting that needs to be adhered to. I am simply wanting to read the file character by character and print it out. When I run the program, I get this symbol:
Code: If I use a printf statement, such as:
Code: printf("%s
", nextChar);
I get a segmentation fault.
My main.h Code:
#ifndef MAIN_H
#define MAIN_H
void scanner(FILE *);
//char getChar(FILE *);
#endif and lastly my scanner.h Code: #ifndef SCANNER_H
#define SCANNER_H
FILE *fp;
#endif
View 6 Replies
View Related
Jan 29, 2015
So i have this code:
if (get_brick_at(Position(row, column)) == NULL)
Where get_brick_at is defined like this:
>Brick& get_brick_at(const Position & p) {
return board[p.get_row()][p.get_column()];
}
Now, of course this does not work since the compiler cannot convert from long int to a Position. So how do i know if the return value of get_brick_at is garbage?
I also have a couple of other situations where i want to return some kind of NULL-like value under certain circumstances.
My question is: How do i handle situations like that?
View 5 Replies
View Related
Mar 21, 2013
Im programming client/server app that client provide the file name then the server send it to client then the client will save it ..this is part of code in client
Code:
char buffer[1024];
printf("FIle is being downloaded ...
");
printf("%s
",buffer);
}
[code],...
So i have 2 problems ::
1st one is when i write to file the file permission i cant define it with data type mode_t ,so the file does not open at all after creation...
2nd one is: the data in buffer is less than 1024 ,the data wrote to buffer but with garbage data . How to make the file read only the real data with garbage ??
View 5 Replies
View Related
Mar 23, 2013
I'm working on my program that takes input of the employees' first and last name, their payrate, their deferred from check and also the amount of hours they have worked which then the gross is calculated and also the taxes are calculated by an external function. In the program design it is necessary to put arrays which I have done, but when i compile I receive warning messages
Code: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'double'
Warning: format '%f' expects a matching 'double' argument [-Wformat] which I believe is causing my program to just give me garbage when I run it. What do those warnings mean?
Code:
/* Name: Arturo
Date: 03/22/13
Purpose: To learn
*/
extern void calculate taxes(float gross,float deferred, float *ft, float *st, float ........i);
void ovtHrs(float *hrs_wrk, float *ovt_hrs, float hrs, float *gross, float payrate);
void netPay(float gross, float deferred, float ft, float st, float ssi, float *net);
[Code] .....
View 9 Replies
View Related
Mar 20, 2013
Here's my code:
struct Member {
char *name;
char *address;
char Interests[][10];//<------problem
int numofInterests;
Numbers digits;
[Code] ....
Now the Program:
newMember.Interests[numofInterests];
newMember.numofInterests = numofInterests;
for(int i = 0; i < numofInterests; i++) {
printf("Enter %s's %i interest: ", newMember.name, (i+1));
[Code] ....
it's a array of cstrings, but i can't figure out how keep it from outputting garbage, i'm assuming it's because i didn't end it with a null terminator but when i did, it didn't work.
View 1 Replies
View Related
Apr 30, 2012
I have a program that runs fine but outputs garbage and skips processes when I input a decimal. It compiles fine and has no errors.
Code:
#include <iostream>
#include <float.h>
using namespace std;
int main() {
int x;
int y;
[Code] ....
View 4 Replies
View Related
Jun 27, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
// Define doubly linked list structures
typedef struct link singleLink;
typedef struct trashLink singleTrashLink;
struct link {
[Code] ....
Alright, my code is almost complete, I just can't get the clearFromList function to work correctly.
Here's what the program does, in a nutshell:
- Create two doubly-linked lists, one to hold numbers 0 through i, the other to hold a randomly generated list of numbers no greater than i to be "trashed". The same number cannot be "trashed" twice.
- Go through the main doubly-linked list and "skip over" the numbers that are listed the trash doubly-linked list (i.e. "delete" them without actually freeing them).
- Free both lists at the end.
I still have to free the trash list, but that's easy. I'm just stuck getting the clearFromList function to "skip over" each number in the main list that is added to the trash list.
View 3 Replies
View Related
Jun 21, 2014
I have a class that uses std::vector. I push back class objects onto the vector but when I try to cout the data members (with get functions) I get garbage values.
Here is the class:
#ifndef JOBS_H
#define JOBS_H
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
class Jobs{
[Code] ....
I know I am missing the implementation of several functions but I'm just testing my vector to see if it is working and it isn't. The getBlockValue() function should output 0 for each job. When I push back one object the output is 0. When I push back 2 objects the output is 0. However when I push back 3 objects I get random values. Why is this? I thought vectors were dynamic?
View 8 Replies
View Related
Feb 14, 2014
I wrote a program that tries to tokenize a mathematical expression, inserting the tokens in a list of strings. The list is as follows:
typedef struct listOfStrings {
char **array;
int size;
} ListOfStrings;
There is even a function to initialize the listOfStrings. The thing is: I'm printing a token every time it is complete and every time it is inserted in the list. The output is okay. However, when all tokens are processed and I call function print_list_of_strings to print the tokens again, the first token is printed with a leading garbage value if the input for the program is "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3". How is this possible? The code for printing the list is as follows:
void print_list_of_strings( const ListOfStrings *const lPtr ) {
int i;
int numberOfElements = lPtr->size;
if ( numberOfElements != 0 ) {
for ( i = 0 ; i < numberOfElements ; ++i ) {
[Code] ....
The list just prints --- if it's empty, although this isn't the case for the program I'm writing. Also, if the input is "1 + 2", everything goes fine. The code for inserting at the list is:
int insert_at_end_of_list_of_strings( ListOfStrings *lPtr, const char *const str ){
int lengthOfStr = strlen( str );
int numberOfElements = lPtr->size;
if ( ( ( *( lPtr->array + numberOfElements ) ) = ( char * )malloc( ( lengthOfStr + 1 ) *
[Code] ....
View 5 Replies
View Related
Feb 1, 2013
How do I detect garbage chars in a CString. Actually I'm reading some data from COM port. In some certain condition it will give some garbage as a version no. Now I need to show _T("N/A") in case of there is any garbage.
My solution is to check for a Valid char or integer. If found its correct else Garbage.
View 11 Replies
View Related
Jan 20, 2014
This code works very oddly.
Code:
#include <algorithm>
#include <cstdlib>
#include <iostream>
[Code].....
View 14 Replies
View Related
Mar 1, 2013
What I need to do to get rid of the infinite loop?
Code:
do {
printf("Enter the number of tests:");
scanf("%d", &test);
if (test< 0 || test> 4)
printf("Wrong number. Please try again!
");
}
while (test< 0 || test>4);
View 9 Replies
View Related
May 30, 2014
See code below:
#include <stdlib.h>
#include <stdio.h>
int main ( int argc, char *argv[] ) {
int P[150] = {}, i, j;
for ( i = 2; i <= 150; i++ ) {
[Code] .....
Using gdb, I noticed that the variable j keep going back to initial value after the interior for loop condition returns false. Why doesn't this for loop terminate right away?
View 6 Replies
View Related
Jan 13, 2015
I have been trying to get this piece of code to work but it seems to be running infinitely. What i'm trying to do is that whenever the iterator points to the map element, I check whether the element is 1 or 0. If it is 0, *do something*. But if it isn't, it should not do anything and proceed to the next element in the map.
//infinite loop - not working!
for (MapType::iterator p = pwCounter.begin(); p != pwCounter.end(); ++p) {
if (p->second.second != 1) {
[Code]....
View 1 Replies
View Related