C :: Change Arrays In Function Int Palin To Pointer

Oct 15, 2014

I'm trying to write a program to test if a string is palindromic using only pointers

Code:

#include <stdio.h>
#include <string.h>
void revstr(char* str)
}

[code]....

I need to change the arrays in the function int palin to pointers.

View 4 Replies


ADVERTISEMENT

C++ :: Pointer Passed To Function Value Doesn't Change

Dec 24, 2014

when i pass a string pointer to a function such as string *str = new string(""); and pass that string to a handleElement() function e.g. handleElement(str), and i change the value in the function it simply doesn't change when the function exits as though it's passing it by value or something, even though it gives the pointer address.. I've now changed the code to use double pointers and pass the reference of the str pointer and it works but it seems ugly to use double pointers for this.

//handles when a new element is encountered when parsing and adds it to the parse tree
bool ParseBlock::handleElement(char cur, string *curString, int count, bool isOperator) {
countNode = new ParseNode(count);
//keep track of numbers and strings if they exist and insert them
if(!curString->empty()){
if(isNumber(*curString)

[code].....

View 2 Replies View Related

C :: Functions Which Change Arrays Without Pointers?

Jan 17, 2014

the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.

View 9 Replies View Related

C/C++ :: LNK1119 And LNK1120 Errors When Trying To Change From Arrays To Struct

Mar 12, 2014

Im trying to take a previous project that was made with arrays and change it to a struct for storage.

Error2error LNK1120: 1 unresolved externalse:my documentsvisual studio 2013ProjectsConsoleApplication15DebugConsoleApplication15.exe11ConsoleApplication15
Error1error LNK2019: unresolved external symbol "void __cdecl getStudentInfo(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,int (* const)[5],float * const,char * const)" (?getStudentInfo@@YAXQAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAY04HQAMQAD@Z) referenced in function _maine:my documentsvisual studio 2013ProjectsConsoleApplication15ConsoleApplication15Source.objConsoleApplication15

I've been trying to research this error message but I haven't been able to find much that pertains to the simple code I have.

Below it the first part of my c++ program that includes everything that I have changed before the error appeared. It seems to be centered around changing the void function at the end

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <climits>
using namespace std;
const int NUM_STUDENTS = 10;
const int NUM_SCORES = 5;
void getStudentInfo(string[], int[][NUM_SCORES], float[], char[]);

[code].....

The final line was originally

void getStudentInfo(string sn[], int ss[][NUM_SCORES], float sa[], char sg[]) {

View 2 Replies View Related

C++ :: Possible To Change A Single Variable From A Pointer?

Dec 2, 2013

I am stuck at a problem where I have two pointers pointing to the same object, and I need to change an int on one of the pointers but point to the same object.

To be more specific, there is an array of Item objects. A long list of items a player can buy. Then, there is the player's inventory, a vector pointer. Whenever a player buys an item, it sets the pointer to the bought object.

The problem arises when he buys two of the same object. I tried to identify the objects with an ID, but it does nothing, because they are just pointing to the same object, and so I have no way of telling them apart.

This is further complicated by the fact that it is a polymorphic object. So, I can't simply make a new every time I buy an object, without making a hassle. Well, at least I am not familiar with that kind of code just yet.

View 18 Replies View Related

C++ :: Change From Array To Pointer Arithmetic?

Sep 12, 2013

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

[Code]....

View 3 Replies View Related

C :: Sorted List - Why Value Of Void Pointer Change

Feb 16, 2014

I have a the following in a header file.

Code:

struct SortedList{
void * data;
struct SortedList * next;
struct SortedList * previous;
int (*compareFunc)(void *, void *);
void (*destructor)(void *);

[Code] ....

In a .c file, I implemented the SLCreate function.

Code:
SortedListPtr SLCreate(CompareFuncT cf, DestructFuncT df){
struct SortedList item;
item.data = NULL;
item.next = (struct SortedList *) malloc(sizeof(struct SortedList));

[Code] ....

In main.c, I try to do the following:

Code:
SortedListPtr list = SLCreate(&compareInts, &destroy);

A bunch other code that does not alter list or it's contents at all.

struct SortedList item = (*list);
void * data = item.data;
if (data != NULL) {
printf(Why did data become not null???
"); }

How come my variable data became not null anymore when I haven't altered it at all....

View 2 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 :: Malloc Pointer To Arrays

Jan 6, 2014

I am confused whether 'malloc'ing an array of pointers and pointer to a group of arrays are the same.

Suppose I need an integer pointer to a group of arrays of 2 elements each.

int (*LR)[2];

So to dynamically allocate this pointer for M number of arrays suppose, then what is the correct syntax?

int M;
scanf("%d",&M);
int (*LR)[2];
LR = (int*)malloc(2*sizeof(int));

Whether this is correct??

View 14 Replies View Related

C++ :: Initialization Of Pointer Arrays

Jan 1, 2014

The below example is an initialization of a pointer array:

char *month_name(int n) {
static char *name[] = {
"Illegal month",
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
};
return (n < 1 || n > 12) ? name[0] : name[n];
}

Here we have an array of character pointers. The pointers are stored in name[i]. And they point to the characters of the i-th string, which are stored somewhere else in memory. But Is the character pointer pointing to the first character in the character string that is stored somewhere else in memory? I assume so because a string itself is an array of characters. And if that is the case, how does the pointer know what the last character should be? Does it just search for the null terminator?

View 2 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++ :: Pointer To Point Dynamic Arrays?

Jan 31, 2013

Do I really need to create a separate pointer to point to dynamic arrays?

T* temp = new T[capacity_ * 2];
T* tIter = &temp; //Do these need to be here?
T* dIter = &data; //Or can I use *(temp + i) and *(data + i)?
(for unsigned int i = 0; i < size_; i++) {
*(tIter + i) = *(dIter + i);
}

View 7 Replies View Related

C++ :: Deleting Class Pointer Arrays?

Feb 3, 2015

If i have a pointer array of classes, e.g. MyClass *foo; and if i try to delete this pointer delete [] foo; does it call a destructor of a class, or wahat happens? this is because i have another pointers in that class which are cleared in destructor.

View 1 Replies View Related

C++ :: Pointer Arrays - Program To Simulate Squares Most Landed On

Jun 8, 2014

I have not been using pointers that long i most of my stuff has not needed them but now they do i need to learn how to use them more. I'm writing a program that simulates the squares most landed on(for fun) and i cant get a method to work because of an array pointer.

The error is no matching function for call to 'GameLoop::Loop(int, int (*)[4])'

Here is the latest version of the code. I've been editing a lot of things so there might be some stupid errors but I've tring everything.

rolling.h and rolling.cpp are just some dice function they are working perfect.

main.cpp

#include <iostream>
#include "Rolling.h"
#include "GameLoop.h"
Rolling Roll;
GameLoop Game;

[Code] ....

View 2 Replies View Related

C++ :: Possible To Change Value Of Variable In Main Using A Function?

Jan 30, 2014

I'm currently writing a poker game and am trying my best to avoid using global variables. I have a few variables in int main() which i was hoping to use to store the value of each players hand. I then created a function which calculates the value of the hand but cannot get this value back into the main function.

For example:

Code:
#include <iostream>
using namespace std;
void getValue(int value) {
value = 4;

[Code] ....

Is there any way i can get the value of value using this function? If not what can I do?

View 8 Replies View Related

C++ :: Value Change After Call Reverse Function

Jul 4, 2013

Which value change after call reverse function.

#include<iostream>
using namespace std;

static void reverse (int len, char *buf) {
char tmp[24];
int i;

[Code] ....

View 10 Replies View Related

C :: Why Integer With Array Change After Passing Through The Function

Apr 12, 2014

Code:

#include <stdio.h>
void define (int integer, int IntArr[0], int *IntP);
int main(void)
{int integer = 0, IntArr[1] = {0}, IntP = 0;
define(integer, IntArr, &IntP);

[Code]...

Why does the integer with array change after passing trough the function and the normal integer doesn't? (I know why the normal one doesn't, but I dont get the array one)

View 1 Replies View Related

C++ :: Change Of Base Function (hex To Octal Or Decimal)

Oct 6, 2014

I need to create a generic function that changes from any starting base, to any final base. I have everything down, except my original function took (and takes) an int value for the number that it converts to another base. I decided to just overload the function. I am Ok with changing between every base, but am slightly off when using my new function to take in a string hex value.

The code below should output 1235 for both functions. It does for the first one, but for the second, I am currently getting 1347. Decimal to Hex works fine - It's just the overloaded function (Hex to anything else) that is slightly off.

#include <iostream>
#include <stack>
#include <string>
#include <cmath>

using namespace std;

void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, int num);
void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, string s);

[Code] .....

View 2 Replies View Related

C/C++ :: Change Function Argument To Negative During Call?

Feb 28, 2015

We are programming a function calculator and my instructor hinted that the add() function is almost exactly like the subtract() function and we would only have to write one function if we "called it in a special way." This got me thinking, can I turn a function's argument to negative during the call to make it subtract?

Example:

void addSub(int &num1, int &num2)
into this
void addSub(int &num1, int -(&num2))

Would this work when passing by reference?

View 9 Replies View Related

C/C++ :: Multiple For Loops - Independent Function Change

Feb 28, 2015

I'm new to writing C. While doing for loops I have found that when I try to do functions and have multiple for loops, even though I have different counters, the independent functions change. For example:

int factorial(n) {
for(i=1;i<n;i++)
fact=fact*i;
return fact;

[Code] ....

The cosine function works out fine but the factorial one spits out crazy numbers, more specifically, 6^1 through 6^10. In my head, the factorial should be a constant throughout the second loop for I guess I am wrong. Why this happens?

View 6 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

View 6 Replies View Related

C++ :: Coin / Money Change Code Doesn't Give Exact Change

Feb 20, 2013

My coin/money change code works when there can be an exact change each time, i.e. when the 1 cent option is available. However, when the change options are only $10, $5, $1, 25 cents and 10 cents, it does not give me what I want for instance, I wanted to get change for $237.80, I was expecting to get:

23 10's, one 5, two 1's and 8 dimes. However, the code below is giving me 23 10's, one 5, two 1's and 3 quarters (there is no option left for the 5 remaining cents).how to fix it?

Code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void change(double cents, int a[]);
int main() {
double Dollars;
double cents;

[code]...

View 14 Replies View Related

C :: Change / Fill List Without Changing Function Type

Feb 13, 2013

I am an IT student currently learning linked list. I have a problem with my code here. After I call addFront() my list doesn't change when I display it. How do I somewhat change/fill my list without changing the function type? I know it works on pointers still messed up with linked list.

Code:

typedef struct node *nodeptr;
struct node{int item;
nodeptr next;};
typedef nodeptr List;
}

[code]....

View 3 Replies View Related

C :: Get Binary Number And Change Its Bits - Calling A Function Not Working

Apr 8, 2013

This code gets a binary number and change its bits. I have a problem with the "bits_up" function . Why this function not working?

Code:
#include <stdio.h>
#include <stdlib.h>
int bits_up(uint first,uint last,int *ptr);
int main(void)
{
uint first,last,bitUD;
int InputBinNumber[4],updatedNum[4];

[Code] ....

View 5 Replies View Related

C++ :: Function To Change Char Array String To Lower Case

Feb 17, 2014

This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). correct this function so it converts string to lower case and doesn't get errors.

#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
void ToLower(char s[]);
int main(){
string y_n;

[Code]...

View 1 Replies View Related

C/C++ :: How To Get Formation From Pointer Function To Main Function

Feb 13, 2014

int example (int [], int, *int,*int,*int,*int);
int main () {
My code will be here
example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work

[Code] ....

View 2 Replies View Related







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