Visual C++ :: Resetting Contents Of Existing Array To 0?
Apr 13, 2015
Is there some quick way of resetting the contents of an existing array to 0? Just to be clear, I'm not initializing the array, it already exists, has content and needs to be reset at 0. Is there a faster way than the code below?
Code:
for(i=0;i<100;i++)myarray[i]=0;
View 6 Replies
ADVERTISEMENT
Sep 10, 2014
I basically want to develop an application which print an existing file on reception of a network event (application will be running on a seven 64 bits PC).
I wonder which application type would be the most suitable (and the simplest) for that (console win32, win32 app, MFC app ...). As this application does not need user intervention (print on network event), I'm not sure that I need a MFC application or a win32 app.
View 9 Replies
View Related
Mar 26, 2013
I have an array of char representing pixels in a bitmap, which I want to modify. I don't think I can just iterate over the array and pass chars into a function individually, because the function needs to take into account the neighboring pixels, too.
I thought of two ways to do this. The first would be to pass the array to the function as an argument, then have the function change it and return it. The trouble is I'm not exactly sure what happens internally when you pass an array to a function and return it. Is it the same array, modified? Or is it a copy of the array, so now you're using twice as much memory?
Alternatively I guess I could have a function with a void return type and pass a pointer to the array. I'm somewhat new to this, but the way I understand it is that a pointer is like the address of a house, while the array is the actual house. So if I give the function the address, it can go to that address and rearrange the furniture inside the house. Then, after the function returns, I can go to that address myself and see all the rearranged furniture, even though the function has already returned.
Is there a problem with the second way? It seems a bit neater, but maybe I'm understanding pointers wrong.
View 14 Replies
View Related
Oct 5, 2012
I am trying to print the content of the CRichEditCtrl v 2.0. The problem is that when I want to use pagination (with A4 pages), the printed text (which is just 4 sample line with 40 chars at most) at the code lTextPrinted =FormatRange(&fr,TRUE); is always lesser than the actual text pointed by the lTextLength variable making the loop run for ever. notice that using the RichEditControl Version 1 it works fine.
Check the code. I am attaching also the full source code at [URL]
Code:
CPrintDialog printDialog(false);
if (bShowPrintDialog) {
int r = printDialog.DoModal();
if (r == IDCANCEL)
return; // User pressed cancel, don't print.
[code]....
View 2 Replies
View Related
Apr 23, 2014
Just wondering how you reset a pointer returned from a 'new' command to the first element in an array (currently I'm just using another pointer).
In the code example below the pointer returned gets moved using pointer arithmetic to clear the array. So what would reset the pointer to the first element in the array of characters?
Size = 100;
char *data = new char [Size];
// clear array
for( int l = 0; l < Size; l++ )
*(data++) = ' ';
delete[] data
View 13 Replies
View Related
Feb 17, 2015
I am not sure why this is happening but I am simply trying to make rounds with my code and have it stop when one of two things, or both, happen.
#include <iostream>
#include "Classes.h"
#include "RNG.h"
#include "select.h"
#include "Fitnesschk.h"
using namespace std;
/*Global Variables************************************/
const int column = 32;
[Code] ....
I've tried resetting and renaming all variables but I don't see any conflict. I tried declaring in different areas but no dice. The other issue I have is that fittest always returns 0 even if the function returns 1. So it infinitely loops. When I go through looking at the variables. the fittest variable never changes even if the function returns 1 and round seems to reset after reproduce is called.
Here is the supporting code.
For Fittracker:
int fittracker(person man[], int row, int column){
for (int y = 0; y < row; y++){
int fit = 0;
for (int z = 0; z < column; z++){
if (man[y].data[z] == 1){
[Code] ....
View 10 Replies
View Related
Feb 18, 2014
I am writing a code with C where I will give an integer and get the binary conversion of it.I tried to fill the binary digits into an integer array.But when I normally print it will give the proper output.But when I try to print the contents of the array it will not produce the proper result.
My code would be as follows.
#include <stdio.h>
#include <conio.h>
int main()
[Code]....
View 5 Replies
View Related
Feb 21, 2015
I'm trying to reverse 25 items that are in my array by using a For Loop and sending 2 of the numbers to a function at a time. The code I have right here, is not working at the moment, I cannot find the problem because i've been staring at my code for too long.
int farEnd = 24;
for (int i = 0; i < 24; i++){
Swap(intArray[i], intArray[farEnd]);
farEnd--;
}
Also here is the code in my function
void Swap(int num1, int num2){
int temp = 0;
temp = num1;
num1 = num2;
num2 = temp;
}
View 5 Replies
View Related
Nov 9, 2014
So I've actually used rand() happily without any problems so far, but now I faced a problem. I have an AI loop that initialized a random number between 1 and 2 at the beginning, so something like this:
while (condition) {
int random = rand()% 1 + 2;
if (random == 1) {
[Code] ....
So this doesn't really work since it doesn't actually assign a new random value. I came across srand(time(NULL)), which resets the seed, but I didn't quite get when to use it. Do I have to call it in every cycle of the loop? I'm not completely sure how this works.
View 2 Replies
View Related
May 10, 2013
it will search the whole file once then i cant get it to reset without restart the program.
cin >> paycode;
while(paycode!=0) {
while(!infile.eof()) {
infile >> search;
infile.ignore(1);
[Code] .....
View 1 Replies
View Related
May 4, 2014
//Introductory20.cpp - displays the contents of a two-dimensional array, column by column and row by row
#include <iostream>
using namespace std;
int main() {
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}};
[Code] .....
I need modifying a program that should display the contents of the two- dimensional array, column by column and also row by row. I need to complete the program using a WHILE statement in the outer loops and a FOR statement in the nested loops.
View 1 Replies
View Related
Apr 9, 2014
I am creating a SpaceShip class, which has arrays for weapon names and damage, and variables for shields power, hull, engine power, and mass. I created two instances of the 'SpaceShip' class, 'ScoutShip', and 'Cruser'. When one of them calls the 'FireWeapons' function, it has the other call the 'TakeDamage' function, but for some reason the 'sheildPower' resets after 'TakeDamage' ends.
#include <iostream>
#include <vector>
using namespace std;
class SpaceShip {
[Code] ....
View 3 Replies
View Related
May 25, 2014
How to reset the board in order to play again without spots already taken.
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
char location[10] = {'0','1','2','3','4','5','6','7','8','9'};
int displayMenu(int &player, int &win);
[Code] .....
View 1 Replies
View Related
Apr 24, 2015
HTML Code:
So I insert values from a vector into a list and into a multiset, and I noticed zero is added to their contents! I had to do a whole lot of debugging to find out where the error was, how can i stop this thing? Code which generates such error...
infact i checked the content of vector ups to be sure that there was no zero in it, but after loading into list combi_t * head, it seems like there was a zero added and this is giving me errors when i call function master_roller...
Code:
void ins(combi_t * &testa, int &numero, int &num, int &no)
{ // if (ricerca(testa, numero) == 0)
//{
combi_t *temp = new combi_t;
temp->val0 = numero;
temp->val1 = num;
temp->val2 = no;
temp->nextPtr = 0;
[Code] ....
View 2 Replies
View Related
Feb 1, 2014
In the function *expandArrayList and *trimArrayList I need to allocate either more memory or less memory to the given array. Right now I am using malloc on a new array and then transferring the elements of the original array to the new array, freeing the original array, and then reassigning it to the new array so it's size and capacity are either bigger or smaller than the original. I feel like there has to be a simpler way to do this with either realloc or calloc, but I cant find sufficient information on either online. Would I be able to use either to make this easier and the code cleaner?
Also, these are character arrays that contain several character arrays inside them, so I was wondering what the best way to transfer the contents of one array to the other would be. I have gone between
Code:
//example
for (i=0; i<length; i++){
newarray[i] = oldarray[i];
}
and
Code: for (i=0; i<length; i++){
strcpy(newarray[i], oldarray[i]);
}
but I'm not sure which one (if either) should work.
The 'ArrayList.h' file that is included contains the structure ArrayList, as well as the function prototypes for the functions listed below.
Here is the structure in ArrayList.h:
Code:
#define DEFAULT_INIT_LEN 10
typedef struct ArrayList {
// We will store an array of strings (i.e., an array of char arrays)
char **array;
[Code] ....
Here is my code:
Code:
//included libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ArrayList.h"
//Create arraylist
[Code]....
View 3 Replies
View Related
May 12, 2013
So I am working on a FUSE filesystem and I currently have the need to load the contents of a text file into an array.
My array initialization looks like: char array[max_entries][PATH_MAX] = {NULL}
The reason I want to pass it by reference is that I want my function to return two values essentially. One a specific char* and the other an array like I initialized. My function proto type looks like:
char* load_meta(char* list[max_entries][PATH_MAX], char* path, int mode);
How I'm trying to call the function:
someChar = load_meta(&array, path_name, 1);
Within the function I try to edit the array by deferenceing it once, like this:
strcpy(*list[i], file_entry); // This seg faults
View 8 Replies
View Related
Aug 2, 2014
read a text file and store the file contents into a 2D array?
100 101 102 103 104 105
106 107 108 109 110 111
112 113 114 115 116 117
118 119 120 121 122 123
124 125 126 127 128 131
Here's my code:
const int ROWS = 5;
const int COLS = 6;
int array[ROWS][COLS];
ifstream inputFile;
inputFile.open("table.txt");
[code]....
When i run the program and try and display the array, it doesn't work.
View 1 Replies
View Related
Jan 10, 2015
I'm coding a hangman game. I'm trying to store user entries so i can output them to show the user what they have already entered. Problem is that it's not display anything at all.
I'm trying to store multiple characters of course, and then display all characters stored.
char guess[27]={0};
cin >> guess[26];
int hit=0;
for(int i=0; i<len; i++) {
if( guess[26] == hidden_word[i] ) {
hit++;
select_word[i] = guess[26];
if(strcmp(hidden_word,select_word) == 0) {
[code]....
EDIT: I also get the error - Stack around the variable 'guess' was corrupted. At the end of the game.
View 6 Replies
View Related
Apr 22, 2014
I am trying to store the contents of a text file into a char array. However the function i am using ifstream member function get(); seems to stop working when fed with certain characters. Is there another solution besides the get() function that will accept all types of characters from files?
char text[1000];
for (int i = 0; i <= textlen; ++i)
{
text[i] = text_in.get();
}
View 3 Replies
View Related
Sep 22, 2014
I need to create an overloaded cout that will print the contents of an array. So I can say output << a << endl;
And it will print the contents of the object a... which happens to be an array.
class info:
class List {
public:
List();
bool empty(); //returns true of false if empty
void front(); //makes current position at beginning of list
void end(); //makes current position at the end of list
[Code] ....
I understand this code, I am simply calling the size method from the program, but i don't know how to pass in the array so that i can print it line by line... simple syntax i am sure... but the whole thing is baffling me... I need to be able to call this on any variation of the class, so it cannot be specific to any one array.
View 4 Replies
View Related
Jan 2, 2014
I am trying to store a large text file into an array so I can count the number of characters.
View 2 Replies
View Related
Feb 10, 2015
I am unsure how to write a function which modifies the content of the 1D character array and puts all of the letter it contains into uppercase. the following are the letters which i am trying to convert.
char text[MAX+1] = {'T', 'e', 's', 't', 'e', 'r', EOT};
The output to this should look like T E S T E R EOT
View 2 Replies
View Related
Oct 20, 2014
Goal:
Read contents from a file and use as the size of a 2d array.
Problem:
C2087: Line 27 : "a1" : missing subscript
C2133: Line 27 : "a1" : unknown size
Code :
int rows;
int columns;
ifstream fObject("inputdata.dat");
fObject>>rows;
fObject>>columns;
char a1[rows][columns];
I am not sure why this is occurring, or if there is a better way to do it.
View 3 Replies
View Related
Apr 29, 2013
I wrote a program to write text contents to file stream through fputs, the file stream address was changed in the middle of writing text content to the stream (11% text content have been put into the file stream), that cause the file stream pointer can be evaluated problem and raise exception on stream validation code in fputs library function, my question is what things could go wrong to make file stream pointer changed its address to something else or a NULL pointer if the file stream have not been flushed and closed.
View 5 Replies
View Related
Aug 5, 2014
#include <iostream>
#include<fstream>
using namespace std;
int main() {
string choice, meaning, word, yesOrno;
char add[20];
[code]....
i have done my best but i have still problem with searching words from previously saved words from user this code it keeps adding but it won't display when i search for.
View 10 Replies
View Related
Jul 6, 2014
I'm trying to edit an existing xml file but with no luck. I'm new to xml environment.
This is the xml content :
<?xml version="1.0" encoding="UTF-8"?>
-<mmp>
<ID>aaa</ID>
<clientID>bbb</clientID>
<time>2004-05-10T17:35:41.29</time>
<session>2000</session>
<Answer>Yes</Answer>
-<Program>
<_id>ppp</id>
</mmp>
I'm trying to change the time and id values and can't do it.I tried almost anything.
View 4 Replies
View Related