C/C++ :: Using Pointers In Stack Program

Sep 7, 2014

I am trying to use pointers in a stack program. But i am failing. my push function takes in the array,item im pushing, the reference to the top, and the size of the array.

void push(char stack[], char item, int *top, int max_size) {
if(&top==(max_size-1)) {
printf("Stack is Full
");
return;
} else {
*top=+1;
stack[*top]=item;
} return;
}

And in the main function i pass a randomly pick char value, print it first , and pass it to the array using the push function

#define STACK_SIZE 10
#define STACK_EMPTY -1
int main(){
char s[STACK_SIZE];
int s_top = STACK_EMPTY; // The index of the top of the stack
int *top= s_top;
int max_size=STACK_SIZE;

[Code] .....

I know I am not referencing and dereferencing correctly and probably other stuff also. but i get these 2 errors:

stack.c: In function "push":
stack.c:23:9: warning: comparison between pointer and integer [enabled by default]
if(&top==(max_size-1))

[Code] ....

View 3 Replies


ADVERTISEMENT

C/C++ :: Using Pointer Of Pointers In A Stack Program

Sep 14, 2014

i wrote a program using pointers in a basic stack program below is the pop and push functions and their calls in main. basically getting random numbers and converting to char characters and inserting them into an int array.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code]....

View 9 Replies View Related

C++ :: Merge Sort Destructor - Using Delete On All Pointers On Stack

Apr 7, 2014

How can I use "delete[]" on all pointers on the stack, using a mixture of top and pop functions or variables

View 2 Replies View Related

C++ :: Write A Postfix Calculator Program Using Stack

Dec 14, 2013

i try to write a postfix calculator program using stack in C++ the in put must be the infix expression but can dont know how to write a infix expression in put.

this is my code :

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <conio.h>
using namespace std;
}

[code]....

View 2 Replies View Related

C++ :: Stack Function Is Supposed To Represent Scope Of Program

Dec 5, 2014

I am trying to make an interpreter. This stack function is supposed to represent the scope of the program, meaning scope of the variables. The START represents a new scope, and FINISH represents the current scope closing. I am trying to do a recursive function in which the stack is updated with each recursive call, which represent a new scope for each call.After i enter a new scope and the scope ends, my program prematurely terminates.

void stack(ifstream& file,Hash& Table) {
string line;
getline(file,line);
int i=0;

[code].....

View 2 Replies View Related

C++ :: Running Infix To Postfix Stack Conversion Program

Mar 27, 2014

I keep getting the same error messages every time on Visual Studio. I don't know where the error is originating. Basically I'm trying to convert an infix expression (A+B-C) to a postfix expression (AB+C-) using stacks.

#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include "Expression.h"
#include "stackType.h"
using namespace std;
int main() {
string fileName;
string infixExpression, postfixExpression;

[Code] .....

View 2 Replies View Related

Visual C++ :: Program That Take Strings From File And Push It Into Stack

Sep 29, 2013

How to write a programme that take strings from file and push it into the stack with number of each sting string before it and later clean the stack?

View 6 Replies View Related

C :: Program To Evaluate Postfix Expression Using Array Implementation Of Stack

Apr 26, 2014

Write a program that evaluates postfix expression using array implementation of stack.

The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.

The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.

Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20

typedef struct{

[Code] ....

View 1 Replies View Related

Visual C++ :: What Is The Usual Maximum Size Of Stack Of A Win32 Program

Sep 24, 2014

I know that if the structure doesn't fit into the stack, it needs to be put onto the heap. But what is maximum size of a win32 stack in usual case?

View 4 Replies View Related

C/C++ :: Payroll Program Net Pay By Pointers

May 15, 2014

My objective is to write a payroll program that among other things sorts the net pay by using pointers. I've already written most the program and have written a working program that sorts the net pay just not by pointers. So What I'll be posting below is my program so far without the pointer sort function.

What I need to do to finish my program is figure out how to add pointers to sort net pay into it.

#include <iostream>
#include <fstream>//file input output stream
#include <iomanip>
#include <string>
using namespace std;
//function prototypes
int readalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[], int n);

[Code] ....

View 14 Replies View Related

C :: Program To Use Void Pointers In A Function

May 14, 2014

As part of my ongoing c programming education, I have written a program to use void pointers in a function,

Code:

#include <stdio.h>
#define MAX_NUMBERS 10
size_t size(void *object);
int main(void) {
}

[code]....

Now I think that the result 4 is the size of the pointer, so I'm confussed as why it doesn't give me the same result as 40.

View 2 Replies View Related

C :: Basic Array Pointers Program

Feb 4, 2014

Code:

#include <stdio.h>
void Swap(int *x, int *y);
int *Largest(int *array, int size);
int main()
{
int a, b, i;
int c[10];
int maxaddress;
}

[code]...

My swap function works fine, but I am trying to find the ADDRESS of the largest element in my array and I am getting an error using gcc on my "return &largest;" and my printf line in my main function.How can I fix this and return the address of the largest?

View 8 Replies View Related

C++ :: Making Program Involving Pointers

Dec 9, 2014

Write following functions

makingArray: this function will return a double pointer which points to a double array and take one parameter- an integer variable which has a default argument of 5. The argument is the size of the integer array. when the function is called, the users input or default argument will be used for the size of the array. The function will initialize all elements of the array with the 'cin' object.

getTotal: this function will return a double and take two parameters- a double array, which can NOT be modified by this function, and an integer variable for a size of the array. This function will calculate the total of all elements then return a double number which is the total.

main: demonstrate functions( makingArray and getTotal) by calling them in a program

View 1 Replies View Related

C++ :: Test Scores Program With Pointers - Calculate Average?

Apr 7, 2013

I have created a program that allows for a user-defined number of test scores as input. After the user enters these scores, the program calculates the average test score. Here is my code:

#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double getAverage(double*, int);

[Code] .....

I am having trouble with the final part of my program. How do I pass the array of test scores to a function that calculates how many people got an A (90+) on the test? The final output should look like this:

The average of those scores is:
The number of A grades is:

View 2 Replies View Related

C++ :: Create Program That Displays Median Of Array Using Pointers

Feb 27, 2013

The assignment is to create a program that displays the median of an array using pointers. Assume the array is already in ascending or descending order.I'm getting errors currently on the bottom two "return median;" statements.The code that I have so far is as follows...

#include <iostream>
using namespace std;
char again;
int getMedian(int*, int);
const int constant = 100;

[code]....

View 3 Replies View Related

C++ :: Pointers And Arrays - Program To Display Sorted List And Average Of Scores With Appropriate Headings

Apr 22, 2014

I am writing a class that dynamically allocates an array that holds a user-defined number of test scores (test scores go from 0 to 10 both included). Once all the test scores are entered and validated (values only between 0 and 10, both included), the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates theaverage of all the scores.The main program should display the sorted list of scores and the average of the scores with appropriate headings.

View 6 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C++ :: Comparing Char Pointers To Integer Pointers

May 21, 2013

I am a little confused while comparing char pointers to integer pointers. Here is the problem:

Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";

When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;

As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};

If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??

View 2 Replies View Related

C++ :: Dynamic Creation Of Arrays Of Pointers To Arrays Of Pointers

Apr 15, 2013

I'm trying to write a function that takes a 32bit address and a data to store at this address.

I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78

then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF

So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.

After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.

The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.

It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.

void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);

[Code] .....

A1 has been declared as
int* A1[256] ;

View 3 Replies View Related

C++ :: Can Declare Stack Globally?

Jul 14, 2013

Can you declare a stack globally?

Code:

stack< int > stk;

View 4 Replies View Related

C++ :: How To Check What Causes A Stack Overflow

Sep 22, 2013

I'm getting a stack overflow error because for large numbers, this code I'm working on allocates too much on the stack.

Is there a way of tracking stack allocations specifically?

Will multithreading solve my problem if each thread is doing the static allocations?

Would I really have to use malloc or new every time I wanted to use memory just to make my code scale to huge numbers?

View 11 Replies View Related

C :: Bit Checking - Stack Overflow

Sep 19, 2013

I usually check if a bit is set using:

Code: bit = (number >> n) & 1; where `n` is the bit I want to check...

But I came across a stackoverflow answer saying:

bit = number & (1 << x); will not put the value of bit x into bit unless bit has type _Bool (<stdbool.h>).

Otherwise, bit = !!(number & (1 << x)); will..

So why is this? why the double !?

View 5 Replies View Related

C :: Corrupted Variable Stack?

Jan 7, 2014

I am getting corrupted stack variable for this piece of bolded code. (starCounter is corrupted)...

Code:
int i;
int j;
int s;

double starCounter[18]= {0};
double lowestfreq = 0;
double frequencyChecker [18] = {0};

[Code] .....

View 4 Replies View Related

C :: Trying To Make A Stack Through Malloc

Oct 27, 2013

I am curious as to what is happening to my pointers and everything once I call malloc to create space for 5 integers to try to make a stack.

Code:

#include <stdio.h>
#include <stdlib.h>
void add(int * TOP, int * stack);
int main() {
int *stack = NULL;
int *TOP = NULL;
stack = (int *)malloc (5 * sizeof(int));

[Code] ....

I am guessing that when I initialize stack to malloc, stack now stores the starting address of where the space is taken out, and also assigns TOP that address too. I get the choice from the user (b) to get the instruction to try to push on the stack. I was told that the if statement in the function checks if the stack has passed the bounds of 5 elements. If not, it assigns the scanned variable and puts it into what TOP is pointing to and increments TOP to the next address. It is not working and am wanting to see where my logic is wrong.

View 4 Replies View Related

C :: Stack Implementation Using Arrays

May 31, 2014

Code:

#include <stdio.h>#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 100
struct stackk
{
int top;
int items[STACKSIZE];
};
typedef struct stackk *s;

[Code]...

View 1 Replies View Related

C :: Write Algorithm Using Stack

Jul 22, 2014

write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B. eg : AABACABAA

View 8 Replies View Related







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