C/C++ :: Printing The Contents Of The Array?

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


ADVERTISEMENT

C++ :: Printing Contents Of A String That Also Exist In A Vector

Jan 27, 2014

For the last part of this problem, if player 2 loses the game of hangman, I need to display the letters they did get right. In order to do that, I believe that I need to traverse vector v for the elements that exist in the string hiddenword, and then print those characters that match.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int letterFill (char, string, string&);

[Code] ....

View 1 Replies View Related

C :: File Contents Printing And Saving With Filename Whenever Try To Send

Jan 2, 2015

I am trying to establish a connection between client and server to send a file to the server from a client. I have been successfully able to send files to the server but i am facing a problem with the the filename whenever i try to send any string to the server and use it in naming the filename at the server side, the string is successfully concatenated but it saves the filecontents in the filename.

for example: i am sending a file hello1.txt to server and the server has to save it as abcxyz.txt as i am sending the "xyz" from the client. BUT Whenever i am doing this ,the file saves as abcxyzfilecontents.txt If i saved in the .txt file "you123" ,my file at server side would save as abcxyzyou123.txt

Here are my codes:

Know that the server code implements a multi threaded server. The functionality to be discussed is defined in myfunc

Code:
server.c:
#include <stdlib.h>
#include <stdio.h>

[Code].....

View 1 Replies View Related

C :: Printing Contents Of A File - Prints One Extra Character Not Present In The File

Feb 12, 2013

I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)

_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60

When printed out, the names are formatted as follows:

lastname, firstname: 90
lname, fname: 100
last, first: 60

However, when I print them out this is what I get:

lastname, firstname: 90
lname, fname: 100$
last, first: 60H

For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.

Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {

[Code]......

View 6 Replies View Related

C/C++ :: Reversing Array Contents

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

C++ :: Display Contents Of Two-Dimensional Array

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

C++ :: Zero In List Contents And Multiset Contents

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

C :: Transferring Contents Of One Character Array To Another Function

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

C++ :: How To Load Contents Of Text File Into Array

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

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 View Related

C++ :: Read A Text File And Store Contents Into 2D Array?

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

C++ :: Store User Input Then Display Array Contents?

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

C++ :: Store Contents Of Text File Into Char Array?

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

C/C++ :: Creating Overloaded Cout That Will Print Contents Of Array

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

C/C++ :: How To Open A File And Store Contents Into Character Array

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

C++ :: Modify Contents Of 1D Character Array - Converting To Upper Case

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

C/C++ :: Read Contents From A File And Use As Size Of 2D Array - Error C2087 And C2133

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

C :: Printing Array With A New Value

Nov 21, 2013

I have an array, ary[size+1] and the original values entered and then another value, x, entered. I found the index of x that makes the array nondecreasing order

Code:

void InsertX (int ary[], int size, int x)
{
int i=0;
int j;
int index;
while(ary[i]<x)

[Code]...

But i can't figure out how to print the new array with x in it, using its index

View 6 Replies View Related

C :: Printing A Box Using 2D Array

May 8, 2013

how to print a box using 2d arrrays. i have to create a tetris game which a im stuck at this stage... so far i have tired i can only come out with this..my coding done so far is as follows:

Code:

#include <stdio.h>
#define ROW 15
#define COLUMN 15
void disp_box (char b[ROW][COLUMN])
}

[code]....

View 2 Replies View Related

C++ :: 3 Dimensional Array Printing?

Oct 25, 2013

I want to make a program that asks the user for a message and then print out a large graphic of that message. For example, if the user types "he" I want to print out

H..................H EEEEEEEEE
H..................H E
H..................H E
H..................H E
HHHHHHHHHH EEEEEEEEE
H..................H E
H..................H E
H..................H E
H..................H EEEEEEEEE

(treat the periods as spaces. I only put them there because it wouldn't separate the H's correctly.)

I will loop this to continue until the user types quit.

1. How would I set this up to store the user input characters into an array?

2. How would I print out the stored data in the shape of the word?

View 4 Replies View Related

C++ :: Printing Out Prime From Array

Nov 4, 2013

I am trying to print out prime from array. I have viewed other sources that are similar and tried to use as reference, but only to confuse myself. This is what i have so far.

void get_output(int&Max,int array[]) {
//array[i]-i;
for(i=1;i<=10;i++) // allow 10 outputs on a line. {
for(int i=0;i<Max;i++) {
prime=true;

[Code] ......

View 4 Replies View Related

C/C++ :: Reading And Printing 2D Array?

Apr 10, 2015

I have a program where I need to read in a 96 number .txt file and perform some operations on it.However, the numbers it reads in are all inncorrect. I got it to work in XCode, but it doesnt work in DevC++ which is where the teacher will be running it. Do I have any major error?

#include <stdio.h>
#include <stdlib.h>
#define rows 8
#define cols 12
void makeArray(FILE*,int[][cols]);
int getScore(int[rows][cols],int,int);

[Code]......

View 14 Replies View Related

C :: Printing Sum Of Variables From Array Of Structure?

Oct 10, 2014

I have an array of structure that takes family information (name, age, and state) after it takes the users input it prints back all of the information that was input and then prints the family members that just live in Texas. After that I am trying to implement a function to average out the ages of all family members but I cant seem to get it right, whenever it gets to that part of the program it just outputs 0. I also tried adding an & sign prior to FAMILY[i].age and got an error of int from ptr with no cast.

Also I realize that the code only shows adding of the family members ages which is fine for now as I am concentrated on getting that to work in the first place.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Global Variables
int i=0, a=0, sum=0;

[Code].....

View 8 Replies View Related

C :: Printing Duplicates Found In Array?

May 8, 2013

I'm having some trouble printing the duplicates found in an array. Specifically, when the value is at more than 2 positions. So if the value 3 is at position 1, 10, and 11 it'll print three messages instead of two:

value 3 at position 1 is also at position 10
value 3 at position 1 is also at position 11
value 3 at position 10 is also at position 11

instead of

value 3 at position 1 is also at position 10
value 3 at position 1 is also at position 11

This is real simple problem, but I can't seem to figure it out. I've been trying to implement another array to 'remember' the encountered position, but I haven't had any luck.

Code:
for(i = 0; i < num_count; i++){for (j = i + 1; j < num_count; j++) {if (num[i] == num[j]){printf("
value %d at position %d is also at position %d", num[i], i, j);}}}

View 8 Replies View Related

C/C++ :: Printing Struct Array After Inputting Information?

Aug 28, 2014

I am doing a data structures program on C++ that is suposse to consist of declaring an array of size five for my credit card structure, that allows the user to input information of five diferent credit cards. I am having a problem with my program, because it runs but after I input the information of the credit card, it does not print out the values that I had input.I dont know where I went wrong with the code or if it is that my approach to solving it is wrong. My code is the following:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct TarjetaCredito

[code].....

View 2 Replies View Related

C# :: Printing All Values Above The Diagonal Line In 2D Array

Apr 11, 2014

I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:

{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}

I'd have to print the elements in italics. I've tried this:

for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}

with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved