C++ ::  Validating Characters In A Stack

Oct 7, 2014

Validation opening/closing brackets.

I had the entire validation working until my professor said that my Pop function had to be a "void" not a "Char". Which destroyed my previous validation and now how to validate this.

I will only be posting the validating function.

All the characters are being thrown in a Stack. So I am using Pop/Top/Push/isEmpty/isFull. That will be shown in my validating code.

Correct Validations:
1. {}()[]
2. [()]
3. {([])}

Incorrect Validations:
1.[)
2.[(]]
3.{])

My main issue is that it validates "[)" correct.

I am pretty positive I must have over complicated my validation.

View 7 Replies


ADVERTISEMENT

C :: String Not Validating Properly?

Mar 5, 2013

1. In main() in the while loop entering 'q' does not exit.

2. in the isbnValidation function. The size check for minimum length words will work, but the check for "Invalid ISBN character" doesn't.

3. Every ISBN entered returns as valid. The formula is supposed to multiply the first digit by 10, next by 9 etc (skipping all the dashes) and add up to a weighted total which if valid will divide evenly by 11.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ISBNMIN 10
#define ISBNMAX 14

[Code].....

View 4 Replies View Related

C++ :: Validating That There Are No Integers Only Numbers

May 20, 2013

I am working on a program where the person enters their name and their gross pay. I had to validate that the gross was a number and contained no letters.

I also have to validate the persons name to see if it contains any numbers. The book I am using has an example with only an if statement that says if it is correct or incorrect. I was trying to use <cctype> and toalpha

I just was wondering if there was a way to put it into a while loop or how i would have it ask the user to input their name again. When i tried it just blew up.

Also in the book they use const int SIZE= 8, but I don't want to put a size on the name if I don't have to.

View 4 Replies View Related

C :: Comparing Between Date Variables - Validating Inputs

Oct 28, 2013

i have a code which compares between these two variables. date1 and date2. The program runs when the user input two correct dates eg: 20/10/2003 20/14/2004 then it will read and display values in between the date. That means if the user enters other characters like alphabets or other weird characters the program will prompt an error and not run.

Only with the correct input(int) then it can run. how can i implement this in that case? probably in real expressions or switch case? This is my code:

/*
* date_compare compares two dates, returning <0, 0, >0 if
* date1<date2, date1==date2, date1>date2, respectively
*/
int date_compare(Date *date1, Date *date2) {
if(date1->year < date2->year) {
//printf("Year is smaller");

[Code] ....

View 10 Replies View Related

C++ :: Validating User Input - How To Declare Array Of Character

Apr 29, 2012

Question simple like that: Let user enter some words from keyboard, one word per line until a '.' (period) entered then print out result, for example:

Code:
Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2

Problem is I don't know how to declare the array of character at the beginning since I don't know neither how many word user may enter nor how many letter of each word. So I go ahead and declared like this: char word[20][50] but I know it is not best way.

Code:

int main () {
char word[20][50]; //array has maximum 20 words, each word maximum 50 character
int i=0, number_of_word;
do {
printf ("Enter a word: ");

[Code] ....

View 3 Replies View Related

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C/C++ :: Find The Common Characters Between Two String Characters

Jul 6, 2014

Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '';
int size1,i,j,temp;
printf ("Input the first string");

[Code]...

View 6 Replies View Related

C/C++ :: Check For Set Of Characters In Array Of Characters?

Mar 26, 2014

I have an array of characters. I am trying to find "houston". The only way I can think of to do this is to use a for loop and check each individual character. Is there an easier way to do this?

char string[] = "Fishing tourism miami atlanta dallas houston";

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

C++ :: Stack Around Variable (Odd) Was Corrupted

Dec 11, 2014

I keep getting the error "Stack around the variable 'odd' was corrupted." how can I fix this here is the program:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;
ifstream infile; ofstream outfile;

[Code] ....

View 1 Replies View Related

C++ :: Stack Implementation With Struct

Apr 7, 2014

I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,

bash-3.2$ g++ stack_str_arr.cpp
stack_str_arr.cpp: In member function ‘void stack::push(int)’:
stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope
stack_str_arr.cpp: At global scope:
stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’

Code:

#include<iostream>
using namespace std;
#define MAX 5
class stack {
public :
stack();

[Code] ....

View 2 Replies View Related

C++ :: Runtime Stack Overflow

Jun 5, 2013

Here is my error message: Warning1warning C4717: 'getx' : recursive on all control paths, function will cause runtime stack overflow

and here is my code I will Bold the part that is giving me problems!

class point
{
public:
point();

[Code]....

View 5 Replies View Related

C++ :: Retrieve A Pointer From Stack?

Aug 28, 2013

In c89/90 is there a way to retrieve a pointer from stack or whatever that would behave as this would once cast to the correct type? This is more of a curiosity than a requirement.

View 6 Replies View Related

C++ :: Mid Of Stack Using Linked List

Apr 1, 2013

I am unable to make any logical algorithm to access middle of stack. I am using stack implemented with linkedlists, I have following functions available for stack like push,pop,top.

View 6 Replies View Related

C++ :: How Memory Is Allocated On Stack

Dec 19, 2013

Suppose if i code like this,

while( true ) {
int x;
// do some thing;
// break on some condition match;
}

whether memory is allocated for ints x one time or each time it hits int x.

View 6 Replies View Related

C++ :: How To Set Stack Size With GCC MinGW

Jun 3, 2014

I'm following a course with coursera (algorithm 1) and my program for the assignment crashes inexorably (many are experimenting the same thing there, the assignment asks for a recursive program for solving a big graph of 500000 nodes). I'm using a version of g++ from MinGW with the editor Geany and windows7. The current setup is:

g++ -std=c++11 -Wall -c "%f"
g++ -std=c++11 -Wall -o "%e" "%f"

How can I set the stack 'unlimited'?

View 5 Replies View Related

C++ :: Recursion To Loop Using Stack

Oct 15, 2014

I want to convert the following program into a non-recursive code using a stack and a loop:

void write(int n) {
if (n>0) {
write(n-1);
cout << n << " ";
write(n-1);
}
}

And here is the code I am using but that currently does not work, and I do not know why:

stack<int> S;
S.push(n);
while (not S.empty()) {
int k = S.top();

[Code] .....

How to simulate that recursion. I thought it was enough to push into the stack the equivalent recursive call.

View 2 Replies View Related

C++ :: Stack Around The Variable (X) Is Corrupted

May 14, 2013

I have been trying to solve a problem when this error came to me :

" stack around the variable 'X' is corrupted "

the program is working correctly and it gave me the wanted result but why does this error appear ?

this is my code :

class interval {
public:
int a;// lower bound
int b;// upper bound
interval(int aValue, int bValue) {set(aValue,bValue);};

[code]....

View 3 Replies View Related

C# :: How To Stack List Items

Nov 18, 2014

I do some research about getting the coordinates from the list items but without success. I would like to make that when i press down my mouse button that little blocks fall "out" my mouse and stack on top of eachother.

that first works. When i press the mouse button i draw squares and the fall to the bottom of the screen, but the stack part not.

here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code]....

View 14 Replies View Related

C/C++ :: Print Even Then Odd Ints From Stack

Feb 19, 2014

Given a stack with an equal amount of even and odd numbers: 4, 22, 15, 3. The output should be in any order: [even], [odd], [even], [odd].

int main() {
Stack<int, 4> stk; stk.ClearStack(); int x;
for (int i = 0; i < 4; i++) {
cin >> x;
stk.PushStack(x);

[Code] ....

Output is:

Wed Feb 19 20:09:10 2014
4 7 5 22 //input
22 5 4 //output

Press any key to continue . . .

I know the logic fails if the first number is not even, but I cant seem to figure out another way to do it.

View 14 Replies View Related







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