C++ :: Print Linked List But As A Vector Of Char

Aug 26, 2013

I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:

char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list

[Code] ....

But when I print that, I get a bunch of weird symbols...

View 7 Replies


ADVERTISEMENT

C/C++ :: Print Name And Ages Forward Then Reverse Using Double Linked List

Apr 28, 2015

I have to write a c program that will allow the user to enter names with ages. The name will be no longer than 40 characters. The name and age should be stored in a node of a doubly linked list. I cant use global data. I need to use 3 subroutines. the first one needs to enter the data and pass the head and tail pointers to the subroutine. the next subroutine needs to print the names and ages to the screen and file output.txt from first to last. the last subroutine needs to print out names and ages to the screen and file output.txt from the last to first.

Im getting several errors when i try to run this program. The first subroutine to get the data from the user and build the double linked list. but i seem to be having issues.

#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int entry(char [][41], int []); // subroutine used for data entry //
void printit(char [][41], int [], int); // subroutine used for data printing //
void reverseprintit(char [][41], int [], int); // subroutine used for reverse data printing //

[Code] .....

View 11 Replies View Related

C++ :: Implementing Recursive Function To Print Linked List In Reverse Order

Nov 29, 2014

Implement a recursive function named void printBack(DoublyLinkedNode<T>* node) for the class DoublyLinkedCircularList which will print out the elements in the list from back to front. The function is initially called with the first node in the list. You may not make use of the previous(prev) links

This is my solution where I got 2 out of a possible 3 marks:

template<class T>
void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node) {
if(node->next == NULL) //Correct- 1 mark
return 0;
else
printBack(node->next); //Correct - 1 mark
cout << current-> element << " ";
}

View 3 Replies View Related

C/C++ :: Print Single Linked List Backward With Functions / Classes - Error Message Regarding Header Files

Oct 11, 2014

I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.

.cpp file:

/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/

#include "linkedListType.h"
#include "orderedLinkedList.h"
#include "linkedListIterator.h"
#include <iostream>
using namespace std;
struct nodeType

[Code] ....

header files:
[URL] .... (error in this header file)
[URL] ....

View 9 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies View Related

C++ :: Creating A Linked List Of Common Elements From Two Other Linked Lists

Apr 29, 2013

I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.

It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.

template <typename T>
LList <T> LList <T>:: common (LList <T> &B)//common fct
{
Node <T> *hunter1 = Head;

[Code]......

View 10 Replies View Related

C :: Insert Linked List Into Another Linked List

Jun 29, 2013

I have a linked list comprised of chars like so...

Code:

node1 - "p"
node2 - "o"
node3 - "p"

I need a function that will take in three perameters...node *replaceChar(node *head, char key, char *str)Stipulations of this function. head is the head of the list, 'key' and 'str' are guaranteed to contain alphanumeric characters only (A-Z, a-z, and 0-9). str can range from 1 to 1023 characters (inclusively). So if I call this function with these perameters..

Code:

node *head == /*the head of the list to be examined*/
char key == "p"char *str == "dog"The new list will look like this...
node1 - 'd'
node2 - 'o'
node3 - 'g'
node4 - 'o'
node5 - 'd'
node6 - 'o'
node7 - 'g'

All instances of 'p' were replaced with 'dog' I have a toString function which takes in a string and converts it to a linked list and returns the head. So assume that you can call the function on str = "dog" so...

Code:

toString(str) == /*this will return the head to the list made from the str*/

If it's unclear what my question is...I am stumped on how to write the replaceChar function the one that takes in three perameters..

View 3 Replies View Related

C/C++ :: Cannot Print Vector Of Vector Of Doubles

Mar 31, 2014

I am trying to print a matrix solution that I've stored in a vector of doubles. The original matrix was stored in a vector of vector of doubles. I want to print to the screen and an output file. Right now it just prints to screen column-style and the output file is horizontal-style. I tried to change the solution from vector of doubles to a vector of vector of doubles like the original matrix but when I run my code it crashes. Here is what I am referring to:

void readMatrix(vector<vector<double>> &matrix, vector<double> &b, int &N, string input) {
ifstream in(input);
in >> N;
matrix.resize(N);
b.resize(N);

[Code] ....

However when I change my printResult function to this (I removed the string argument because I just want to get it working to the screen first):

void printResult(vector<vector<double>> &sol, const int N) {
//ofstream out(output);
//int j;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++){

[Code] ....

The program crashes. Am I even printing the matrix correctly?

View 4 Replies View Related

C :: Linked List / Adding Element To Beginning Of List

Dec 31, 2014

Code:

// Write a function called insertEntry() to insert a new entry into a linked list.

Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.

// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.

(Hint: Think about setting up a special structure to point to the beginning of the list.)

#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};

[code]...

This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?

View 8 Replies View Related

C++ :: How To Print Unsigned Char

Apr 23, 2013

How do I print an unsigned char in c++? E.g.

unsigned char a[100] = "acdef";
wprintf(L"a is %u
", a);
wcout << "a is " << a << endl;

gives

a is 2880488
a is 002BF3E8

and not

a is acdef
a is acdef

??

what is the difference between unsigned char and char?

View 6 Replies View Related

C/C++ :: Read And Print A Char Array

Nov 25, 2014

In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.

I'm having an hard time to read a pixel map, or atleast ro print it on my main function.

I have a read_xpm function, which is given, therefore, working.

char *read_xpm(char *map[], int *wd, int *ht)

then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:

static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",

[Code]....

I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.

View 3 Replies View Related

C++ :: Linked List Delete List?

May 30, 2013

I'm working on a linked list and was wondering how this looks to everybody else for a deleteList function.

void deleteList(Node* head)
{
Node* iterator = head;
while (iterator != 0)

[code].....

View 6 Replies View Related

C :: How To Print The Max Number Row In Relation To The Char Arrays Row

Mar 30, 2013

I have most of the code working properly, but I'm having trouble with a certain area. Currently I have multiple 2D arrays. One is a char array and the other is an int array. In the int array I have to find the max number in each column, which I've done. The problem is, I need to print the max number's row in relation to the char array's row.

For example,

Code: int array[2][3] = {60 50 30 0 100 1}

The max numbers are 60, 100, 30.

char array[2][length+1] = {nameOne nameTwo}

How it needs to print:

nameOne has max score of 60.
nameTwo has max score of 100.
nameOne has max score of 30.

I just can't understand how to compare the two arrays in the right way, so it'll know that nameOne is associated with the numbers in row 0 and nameTwo in row 1, etc.

View 1 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C++ :: How To Concatenate Two Vector Char

Dec 1, 2013

This seamed as a simple thing but i am getting something i did not expect: Example:

Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x

StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );

cout << StrJoin.size()<<"
"; // x*2

All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.

View 3 Replies View Related

C++ :: How To Make Vector Of Char

Jun 8, 2013

let say

char temp[8][8];

and you want to make vector of this char

vector<????> boardVec;

View 2 Replies View Related

C++ :: Program Compiles But Refuses To Print Out Char Grades?

Nov 10, 2014

#include <fstream>
#include <ostream>
#include <iostream>
#include <iomanip>

using namespace std;

const int NAMESIZE = 15;
const int MAXRECORDS = 50;

[Code] ....

View 2 Replies View Related

C++ :: Vector Of Integers - How To Print Indicators

Apr 8, 2014

I have a vector of integers, which can take values 0 or 1, say

0 0 0 1 1

I need to print indicators, telling in which position 1-values occur. So

0 0 0 1 0
and
0 0 0 0 1

View 11 Replies View Related

C++ :: Print Values From A Vector Of A Struct?

Apr 5, 2013

I'm trying to print values from a vector of a struct and I don't really know how to do that. Here is a simple code that I have for now to test how to add data to the vector then attempt to print it out.

#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <fstream>
using namespace std;
struct Employee//employee data

[Code]...

View 2 Replies View Related

C/C++ :: Getting A Vector To Print Out 12 Items Per Line

Sep 2, 2013

I'm having problems fully comprehending how to do this task (I'm only going to include my function code since that's the basis of my problem). How should I go about getting my vector to print off 12 items per line. Here's my current function.

void printVec(const vector<int>& v) {
    for(unsigned i=0; i < 12;i++)
        cout<<v[i]<<" "<<endl;
}

View 2 Replies View Related

C :: Structs And Linked Lists - Only Print Out Last Inserted Node

Oct 2, 2013

Why my linked list isn't actually linking together. What I mean is that when I print it out, it will only print out the node that was last inserted into the list. Below is a snippet of my code..

Code:

struct Sort_list{
int null_bool; //if 0, then not null; if 1, then null
int val1; //int
struct Sort_list *next;

[Code] ....

I'm also working with void pointers, but I don't think it's really the issue. So, just ignore those parts..

View 14 Replies View Related

C++ :: Transform TXT File To Char Vector?

Aug 17, 2013

I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

[Code].....

View 7 Replies View Related

C++ :: String To Multidimensional Char Vector

Feb 3, 2013

I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:

vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "

[code]....

However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?

View 7 Replies View Related

C/C++ :: Sending Char And Storing It In Vector

Feb 3, 2014

I've got something I'm trying to accomplish, but crashes my program.

I've got my server and client code.

Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.

The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.

Client storing vector pseudo-code:

vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {

[Code]....

This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.

View 8 Replies View Related

C++ ::  How To Print Out Elements Of Vector Of Type Pair

Oct 7, 2014

here is a piece of my code:

while(T--)
{
std::vector<std::pair<int, int> > *dragon;
std::vector<std::pair<int, int> > *villager;

[Code]....

I now wish to print the elements of the vector. How do I do it?

View 2 Replies View Related

C++ :: Deleting Vector With Char - Segment Fault

Apr 19, 2012

The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *

Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)

[Code] ....

View 7 Replies View Related







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