C :: Print Pascal Triangle And Stores It In A Pointer To A Pointer

Nov 27, 2013

I have to write a program to print pascals triangle and stores it in a pointer to a pointer , which I am not entirely sure how to do. I also have to write the file and read it, then create a binary file. Assignment is attached. I am not the best with programming and especially with pointers. I will post my code below.

Code:
#include <stdio.h>
#include <stdlib.h>
void writePascalTriangle(char *fileName, int heightOfTriangle, int **triangle) {
FILE *fp;
fp=fopen("writePascalTriangle.txt", "w");

[Code] ....

View 4 Replies


ADVERTISEMENT

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

C++ :: Pass Object To Class Which Stores It In Container As Unique Pointer

Jul 24, 2013

class A (abstract)
class B : A
class C {
void add ( A(&*?) a )
std::vector<std::unique_ptr<A>> data; //unique_ptr<A> because A is abstract and therefore vector<A> isn't possible
}

upper situation. What is the best way to pass add an object of class B to C?

with C::add(A* a){ vector.push_back( unique_ptr<A>(a) ); }
and
int main() {
C c;
c.add( new B() );
}

This works, but i don't think it's very nice, because you could delete the pointer in main. What happens then with the unique_ptr? I could probably make C::add( std::unique_ptr<A> u_p ); but maybe it can be avoided that the "user" (in main() ) has to create the unique_ptr itself.

View 10 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C++ :: How To Display Pascal Triangle Using 2D Array

Aug 16, 2014

how can i display a pascal triangle in forloop?

Here's my code.

#include<iostream>
using namespace std;
void print(int a[3][3])

[Code].....

View 1 Replies View Related

C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.

Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));

[Code] ....

View 7 Replies View Related

C :: How To Check If Return Value Actually Points To Pascal Triangle

Nov 27, 2013

I have been trying for hours to create a specific prototype program that determines a pascal's triangle for a give number of rows. However, prototype must have the return type of int**. I just recently learnt about pointers, why my attempt of the function doesn't work. As well, i am not sure how I can check if my return value actually points to the pascal triangle.

Code:

#include <stdio.h>
#include <stdlib.h>
int **getPascalTriangle(int n)
}

[code]....

View 1 Replies View Related

C++ :: How To Use Function With Pointer Parameter To Print Array

Jul 20, 2013

The printArray function should take in the dynamically created array and the size of the array as parameters. It should print out the contents of the array.

#include <iostream>
#include <string>
using namespace std;

[Code].....

My problem is that how to write the code to print the array using pointers. I've been stuck for awhile trying to figure it out.

View 2 Replies View Related

C++ :: Return Struct Pointer From A Void Function And Print

Mar 17, 2013

i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code

struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}

Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...

View 3 Replies View Related

C/C++ :: Const Pointer Pass By Reference In Print Function

Apr 21, 2014

I am trying use a print function to print out data in a struct. My questions are:

1. I have to use pass by reference. For the print function, I am passing the struct pointer as a reference, however, I don't want the print function to accidentally change anything. How can I make it use const to ensure that?

2. The deleteprt function doesn't look right to me. I feel like it should just be delete ptr not delete [] ptr.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
struct Inventory {

[Code] .....

View 9 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Calling Defined Function Pointer From Another Pointer To Class Object?

Aug 19, 2014

I am attempting to implement function pointers and I am having a bit of a problem.

See the code example below; what I want to be able to do is call a function pointer from another pointer.

I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.

class MainObject;
class SecondaryObject;
class SecondaryObject {
public:

[Code]....

View 10 Replies View Related

C++ :: Get Pointer That Iterator Points To And Store In Pointer Variable?

Apr 19, 2014

I'm making a system like twitter for class called ShoutOut.com I want to be able to get the PublicShoutOut pointer pointed to by the start iterator and assign it to firstShoutOutToDisplay and secondShoutOutToDisplay because I need that in order to pass the pointers to one of my functions. When I step through the debugger the values in start are all default values like "" and so are the values in this->firstShoutOutToDisplay but the message that start points to is being output just fine.

EDIT: got rid of irrelevant code. Am I using the correct syntax to do this?

if (start != finish) {
//getting these because a shoutout needs to be passed to the function that displays
//options for a shoutout
this->firstShoutoutToDisplay = (*start);

[Code] ....

View 2 Replies View Related

C++ :: How To Convert Void Pointer To Int / Double / String Pointer

Mar 7, 2013

I have a function:

const void insertStuff(const void *key, const int value){
// I want to convert the void pointer into one
// of three types of pointers(int, string, or double)
switch(value){
case 0:
int *intPtr = key;

[Code] .....

But this causes an error of: "crosses initialization of int*intPtr"

What's the correct way of implementing this?

View 1 Replies View Related

C :: Access Element Of Array Through A Pointer To A Pointer

Dec 25, 2013

i have been fiddling with pointers but I don't understand how the proper syntax is written when I want to acces an element of an array through a pointer to a pointer...The code is all mostly just random bs for learning purposes. I marked the problem "// THIS LINE"

Code:

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define MAX_DATA 100
int find_average(char *iden, ...) {

[Code]...

View 2 Replies View Related

C :: How To Declare Two Dimensional Array Using A Pointer To A Pointer

Jul 16, 2013

This is a sample program that declares a Matrix as a structure with an array as a pointer to a pointer. The following program is supposed to store a matrix in the structure "_Matrix" and later print the matrix just entered but it fails giving me a "segmentation fault". The sample code is given below

Code:
#include <stdio.h>
#include <stdlib.h>
struct _Matrix {
int row_size;
int col_size;
int **mat;

[Code] ......

View 1 Replies View Related

C++ :: Pass Matrix By Reference Using Pointer Of Pointer

Jun 20, 2014

i really don't know why has a error in my code, that pass a pointer of pointer (name of a matrix with 2 dimensions). Here is the source code of a simple example where appears segmentation fault when execute (but compiles normal):

#include <stdio.h>
#define LINHAS 3
#define COLUNAS 5
float a[LINHAS][COLUNAS];
void zeros(float **p,float m, float n){
int i,j;
for(i=0;i<m;i++)

[Code]...

View 6 Replies View Related

C/C++ :: Copying A String From A Pointer To New Pointer

Mar 4, 2015

I need to make a copy of a string that is defined by char *full and copy it into a different pointer defined by char *duplicate. I have written code to do this however it will not work and i cannot figure it out my code is as follows:

char *duplicate = (char *)malloc(strlen(full) + 1);
strcpy(duplicate, full); /*Make second version of full*/
char *Ptr = strtok(duplicate, " "); /*Split duplicate up*/

I have a full program written but i know this is where the problem is because i have used printf statements to see where the program fails. I get no errors and it compiles successfully but it hits this point of the program and it just stops and windows automatically shuts down the program.

char *full is pointing to:
"To be, or not to be? That is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,"

I need to duplicate the string because i need to use strtok but i will need the original string later on so i need an unaltered version.

View 9 Replies View Related

C++ :: Looping Through 2D Array Using Pointer To Pointer

Jan 3, 2013

I have the following code :

Code:
#ifndef TDYNAMICARRAY_H
#define TDYNAMICARRAY_H
namespace Massive {
template<class T>
T **AllocateDynamic2DArray(int nRows,int nCols)

[Code] .....

I wish to know how to traverse or loop through a dynamic 2D array using pointer to pointer as returned by the code above. Like I would in a static T[20][20] 2D array.

View 8 Replies View Related

C :: Print The Star Equilateral Triangle

Dec 23, 2014

I use photos to express it. The answer is:

Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {

[Code]....

View 3 Replies View Related

C++ :: Print Equilateral Triangle With Asterisks?

Feb 22, 2013

how can i print an equilateral triangle with asterisks .

View 3 Replies View Related

C :: Print Triangle Pattern Using One Loop And Recursion?

Dec 18, 2013

Q.print triangle pattern using one loop and recursion

eg: 5

Code:

#include <stdio.h>#include <conio.h>
void pattern(int n,int N) {
int i,c=1;

[Code]....

View 8 Replies View Related

C++ :: Void Triangle - Print Class Function

Sep 1, 2013

//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;

Point::Point() { //Initialise the point to the origin.

[Code] ....

void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"

How do I accomplish this? When i test with cout << _point1.print(), there's an error:

[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'

View 4 Replies View Related

C :: Calling Function Via Function Pointer Inside Structure Pointer

Mar 14, 2013

I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.

Code:

position = hash->(*funcHash)(idNmbr);

The function will return an int, which is what position is a type of. When I compile this code,

I get the error: error: expected identifier before ( token.

Is my syntax wrong? I'm not sure what would be throwing this error.

View 3 Replies View Related

C++ :: Cast Base Class Pointer To Derived Class Pointer

Feb 6, 2015

I create an instance of a base class (not derived class) and assign it to base class pointer. Then, I convert it to a pointer to a derived class and call methods on it.

why does it work, if there is a virtual table?

when will it fail?

// TestCastWin.cpp : Defines the entry point for the console application.//

#include "stdafx.h"
#include <iostream>
class B
{
public:
B(double x, double y) : x_(x), y_(y) {}
double x() const { return x_; }

[Code] ....

View 14 Replies View Related

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

Jun 5, 2012

"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);

[Code] ....

These codes give these errors:

error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'

These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"

I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.

View 3 Replies View Related







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