C++ :: Increasing Variable Number In C Files
Oct 10, 2014
Im having trouble on getting the quantity up of the variable "item.iqty". For example the current quantity is 5 and in this function, the user inputs a number and it should add to the variable "item.iqty". So if if the user inputs 2 then the current quantity should be 7 now but in my program it hasnt changed. its still 5
void addQty(FILE *fp)
{
int num, qty, r, c, n;
bool found;
[Code]....
View 3 Replies
ADVERTISEMENT
Feb 19, 2014
So I have a template, part of a larger code, that is designed to calculate the number of multiplications it took to reach a certain number. The problem is, whenever I execute the program, mults is always printing out a strange number, perhaps its actual address.
template <class T>
T power3(T x, unsigned int n, unsigned int& mults) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == 2){
[Code] ....
View 10 Replies
View Related
Sep 7, 2013
I was trying out programs based on extern and as i understand, this is useful when accessing variables across multiple files having only one definition. But i tried a simple program as below without "extern" and thing seem to work when i expected it would fail during linking process
Code:
file5.c
1 #include <stdio.h>
2 #include "var.h"
3
4 int main() {
5
6 printf("
File5.c a = %d", a);
[Code] .....
As i have included "var.h" in all header files without extern, "int a" would be included in both the .c file and during linking, compiler should have thrown a warning or error message but it compiles file without any issue. Shouldn't var.h have the following "extern int a"?
View 8 Replies
View Related
Sep 5, 2014
I'm trying to implement a linked list using my own node class. I've created functions to add to the head and tail, return the size of the linked list as well as the value stored within the current pointer.
However, my problem is that when I wrote a test program to see whether my list worked, my list did not appear to increase in size past 1 item in the list.
this is the test program I wrote:
int main() {
int counter,
data;
linkedlist *my_list = new linkedlist();
cout << my_list->size() << endl;
for (counter = 0; counter < 5; counter++) {
[Code] ....
I'm sure it's probably something simple that I've overlooked . But I'm still relatively new to the concept of dynamic memory allocation.
View 2 Replies
View Related
May 2, 2014
class Album{
private:
char albumName[100];
Song* List;
int numSongs;
public:
Album(char*);
~Album();
[Code] ....
And everytime I create the class it can have only one song because I set numSongs to zero.
View 2 Replies
View Related
Dec 6, 2014
Code:
#include <iostream>
using namespace std;
int j;
int n;
int recursive ( int arr[j] );
int main() {
int i;
int arr[10000];
[code]....
This is how I tried making the program..
I want it with a recursive function
I want if the sequence is non decreasing return true else return false
View 10 Replies
View Related
Jun 1, 2014
I am trying to make a double array, but I keep getting an error Segmentation fault (core dumped) when I make more than 105 elements in the array. I need to make 114 elements.
I am building my array with myarray[999] and increasing the number doesn't seem to do anything.
How can I store more elements in my array?
View 1 Replies
View Related
Nov 15, 2013
I am new to programming all together but i have been writing a program in c++ and im coming up against an issue with my array.
#include<iostream>
#include<iomanip>
#include<string>
using namespace
int main () {
int a ;
int b ;
char answer ('Y') ;
[Code] ....
I am trying to get the program to increase say year one by 1 when the condition is met i have tried
if ( a >= 70 && a <= 100 && b == 1)
{grade [0][0] = 0 + 1;}
and
for (grade[0][0] = 0 ; a >= 70 && a <= 100 && b == 1 ; grade [0][0]++)
{grade [0][0]= 0 + 1 ;}
Now all that i want is that the array will take the information from int a and int b and then add 1 to the appropriate part of the array . I have tried putting it in deferent places but its not working for ether. the program will run but it will not add to the array.
View 13 Replies
View Related
Apr 23, 2012
We have socket server which is developed in c# .net 3.5.
I see server memory keep on increasing whenver client disconnectes and connects.The server disconnects client if client didn;t send valid credentials.
When client is trying to connect with invalid credentials the memory is keep on increasing.
Here is the code that handles disconnection.
try {
if (state.workSocket != null) {
log.DebugFormat("ssl socket displose,{0},{1}", Doomed, IP);
state.workSocket.Shutdown(SocketShutdown.Both);
state.workSocket.Close(1);
state.workSocket = null;
log.DebugFormat("ssl socket displose complete,{0},{1}", Doomed, IP);
[Code] ....
View 7 Replies
View Related
Sep 12, 2013
All I have so far is a rectangle that prints 5 stars in length and 20 lines in length. What I want to do now is have each new line print an extra space more than the line before it and then print 5 stars.. This is what I have so far:
Code:
#include <stdio.h>
int main (void){
int i;
for(i=1; i<=20; i++){
printf("*****
");
[code]....
View 1 Replies
View Related
Mar 25, 2013
Any examples of a c++ program that uses recursion to find the longest increasing sequence from a grid in a file. Like
2 4 6 8
10 12 14 16
18 20 22 24
I have to use a structure named Point and a structure named Sequence.
const int MAXROWS = 4;
const int MAXCOLS = 4;
const int MAXFILENAME = 255;
// Structure used to define a point (x,y) in the grid.
typedef struct {
int x, y;
[Code] .....
View 1 Replies
View Related
Apr 14, 2014
Windows 7, 64 bits, Visual Studio 10.
I have a problem to read a large number of binary files, process them and store them under a new name. The program and routines go very well for 505 files. After reading 506 files, the program now refuses to read the next file. I have 16 Gb of memory and tried to close all other programs and restart the PC. it always stops after 506 files (512 files would be more understanding in a way...).
Here is my code. I have tried many things without success. This is only part of the loop that stops. The if test if (myfile.is_open() returns false by some reason. I can start the process again starting with the file that does not open and then it stops again after 506 files.
char * tfiBlock;
ifstream myfile (OrigFilename, ios::in|ios::binary|ios::ate);
if (myfile.is_open()) {
int lengde = myfile.tellg();
tfiBlock = new char [lengde];
//static char memblock [size];
[Code] .....
Clean up procedure:
delete[] tfiBlock;
Are there any limits to how many files that can be opened, or is it maybe someting to be set in the compiler?
View 5 Replies
View Related
May 21, 2014
I want to read a folder that contains large number of tif files. (say 1000 tif images) requirement is to read all files and store in a array/array pointer.
View 1 Replies
View Related
Jan 14, 2014
We have a program that sequentially processes a large number of files (currently about 700 expected to increase to about 1500). The program performs the same processing on each file (and doesn't involve any other file) which is io-bound and not cpu-bound. This process takes several hours and it is normally performed overnight.
I've refactored the program so that the processing for each file is done within its own thread (ie one thread created for the processing of one file). This gives rise to many hundreds of io-bound threads. This refactored program is working with no errors reported and has reduced the total processing time down to about 10 minutes.
Any problems that might arise having this number of threads (700 to 1500) created/running?
View 14 Replies
View Related
Jun 9, 2013
How do i get the fraction for any decimal number in a variable?
Code: Code: #include<iostream>
using namespace std;
int main()
{
double x = 1/6;
cout << x;
cin.get();
}
View 1 Replies
View Related
Feb 25, 2014
In C how can I initialize a variable that is not a letter or number? For example with a number I can :
Code:
int i = 5;
for ( i = 0; i <=5; i++ );
printf( "%d", i ) This would display a row of 5's
but what if I wanted to display a row of -----? What I am trying to do is read in a simple txt file, around the file I want ----1----2-----3 ect ect on the top ----a----b-----c down the side Then I want to be able to change the file at lets say position c2 and save it. This is the early stages of my attempt to set up a editable table.
View 3 Replies
View Related
Apr 21, 2014
Write a function write with variable number of arguments that takes a string first argument followed by any number of arguments of type double and prints on the screen a string formatted by the rules described below. The first argument may contain formats in curly braces of the form {index[:specifier]}, where the square brackets show optional parts (this is :specifier may be missing), and index is the sequence number of an argument of type double (starting from sequence number 0).
Rules for formatting: In the printed string the curly brackets and their content will be replaced by the argument with the given index, formatted according to the given format specifier. If the format specifier is missing, the argument will be printed with its default format. For example:
write("The number {0} is greater than {1}.", 5, -3);
will print
The number 5 is greater than -3.
write("There are no format specifiers here.");
will print
There are no format specifiers here.
The format specifiers and their meanings are listed in the following table
Specifier MeaningFormat Output for 1.62 Output for 2.0
none default {0}1.62 2
ccurrency{0:c}$1.62 $2.00
escientific{0:e}1.620000e+000 2.000000e+000
ffixed point{0:f}1.620000 2.000000
iround to int{0:i}2 2
Limitations: You may limit the maximum number of arguments your function can process to a certain value, for example 10.
Suggested extensions:
-Add an optional alignment specification in the format , e.g., make the format of the form {index[,alignment][:specifier]}, where alignment is an integer specifying the width of the field in which the corresponding argument will be printed. If alignment is positive, align to the right, if it is negative, align to the left.
-Accept an optional integer after the specifier letter, specifying the required precision in the output. For example, {0:f2} will print the number 1.6234 as 1.62, but {0:f5} will print it as 1.62340.
View 1 Replies
View Related
Apr 23, 2013
I'm a basic C++ programmer, and I am stuck on this problem. You work for a company that collects a set of numbers. The numbers are located in a data file named "./Data_File". The data file contains two columns. how do you count a certain number on the left column.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
#define DATA_FILE1 "./Data_File"
#define SUCEESS 0
#define FAIL 1
[code].....
View 1 Replies
View Related
Jan 9, 2015
how to make a program in which a user is prompted to input four numbers like 1234 and then print those four numbers one by one on screen using only one variable..??
For example:
1
2
3
4
in ascending order...
I've done that with two methods but i am not sure whether the methods were correct..
View 1 Replies
View Related
Jun 4, 2013
I am writing a math program, using variables of type double, and had initialized all variables to 0.0.
I now realize that not all results will be valid.
Is there a way to explicitly assign a variable of type double a non-numeric value, for example, "NaN", "Undefined", or "Unassigned" or something like that?
That way, when I read through the printout of results, I will realize the "NaN" results indicate a valid solution was not found. Whereas a 0.0 might not stand out.
I'd hate to have to go back and delete the initialization, and then re-assign 998 values just for the sake of 2 non-solutions.
View 3 Replies
View Related
Jul 18, 2014
I have a simple problem about memory allocation.In the function Nr_elements() i assign a value which represent the elements of array. The pointer p is initialised with the address of variable n, but when i compile i dont know why but dont work. This function return a pointer.
Code:
#include<stdio.h>
#include<stdlib.h>
int *Nr_elements();
int *allocate(int);
void deallocate(int *);
[code]....
View 3 Replies
View Related
Mar 6, 2015
Program that has the user enter 5 digits then asks the user what they want to know about the 5 digits. My issue is when the program goes to print the value, its a totally ill related number
10 34 8 17 50
program prints out:
2 for smallest
79 for largest
119 for sum
23.80 for average
Code:
#include <stdio.h>#include <stdlib.h>
int main(void)
{
int smallNum, largNum, count=0, sum=0, value, choice;
double avgNum;
printf("Enter 5 integers
");
printf("
");
[Code]...
View 7 Replies
View Related
Mar 3, 2013
I am forking 3 times in a loop like this but the variable "count" does not increment, it stays on '1' and therefore this is an infinite loop, and this simple thing dont make sense to me.
I have checked so that the pointer address is the correct one every loop.
Code:
void increase(int* x) {
*x += 1;
}
main() {
int pid, i, number = 0;
[Code] .....
View 8 Replies
View Related
Mar 6, 2015
I need to create dynamic string by given format(%d,%s,%f,%lf,%c) using variable number of arguments in function. This code gives me an error(main.exe has stopped working):
Code:
#include<stdio.h>
#include<stdarg.h>
#include<string.h>
#include<stdlib.h>
char *form(char *format,...);
char *form(char *format,...)
[Code]...
I assume the error is in functions(itoa,fcvt,ecvt).
View 1 Replies
View Related
Oct 23, 2014
I need to create a function that takes as an input a variable number of scalars and returns the biggest one. Just like std::max() does for 2 elements, but I need it for an undefined number of elements, can be 2, or 5, or 10 etc.. How to approach this?
What I need it for: I'm working with a bunch of vectors, maps, etc. and I need to find out which has the most elements. So I was thinking that I should end up with something like
int biggest = max(vector1.size(), vector2.size(), map1.size(), ...);
View 8 Replies
View Related
Nov 29, 2013
i want to assign number of bits by a variable in bitset? how to do that? like bitset<4> foo; instead of 4 i want to use some variable and later on by user i want to assign it! boost library or any other library!
View 1 Replies
View Related