C :: Pointer To String In Functions

Feb 10, 2015

I made this example code to illustrate my question:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Right(char* In, char* Out, int Position){
Out=&In[strlen(In)-Position];

[Code] ....

Well, I guess the code explains it all. I want b to be the last three characters of a using a function called "Right".

Doing exactly the same thing without the function involved works fine. I just let b point to the third last character of a.

Why does the function not work?

View 9 Replies


ADVERTISEMENT

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++ :: Can't Pass To Functions With Pointer

May 25, 2013

I get a run time error saying something about memory locations when I run this program.How can I make this program work using pointers?

//this program converst miles to km
#include<iostream>
#include "std_lib_facilities.h"

[Code]....

View 1 Replies View Related

C/C++ :: How To Use Void Pointer Functions

Sep 27, 2014

int (*cInts)(void*,void*);
cInts= &compareInts;

int x=(cInts)(2,5); //This wont work. I tried a bunch of other things
printf(x);

View 5 Replies View Related

C :: Difference Between Functions As Pointer And Normal Function

Aug 30, 2014

whats the difference between functions as pointer and normal function, eg:

void function1(void)
void *function1(void)

What is the difference between the two?I'm doing parallel programming and we use pointer functions (void *function1(void)) when calling threads. I want to why it is done.

View 6 Replies View Related

C++ :: Class Member Functions With Pointer Parameters?

Jan 30, 2013

Here is the assignment: (3pts) Given the following class header file, write the class’ source code for each of the accessor and mutator functions listed. (How the functions have listed their parameters, varying between passing by reference and by value.) Don’t forget to comment your code – it counts!

class Album {
private:
char * artist; // band or singer’s name
char * title; // title of the album

[code]....

The input will be an array. My questions: First, am I on the right track?

When using (char * a) for a function, for example, this is passing the address of a, correct? so then *artist=a; changes what the address of a points to?

also, the functions are bool when I would expect void. Why? for all of the set_" " functions, the parameter is *... but for set_record_label it is *&. That appears to be a mistake to me. Is that right?

what is the difference between *& and * as parameters?

View 5 Replies View Related

C :: Calling Functions With Arguments Using Pointer Variables As Operators

Feb 2, 2013

There are, or course, better ways to do this, but I need to stick to some rules:

(1) Use only pointer variables and not arrays or structs.
(2) Use the three functions shown--regardless of easier methods.

The program should ask for some input, operate on those numbers, and then display the results. I know I am confused over these things:

(1) All that syntax using '*' and '&' or neither.
(2) How to use the char type correctly.
(3) How to use a char type input as an operator (a + b).
(4) How to use the pointer of the operator variable (+,-,*,/) in an actual equation.

Code:
#include <stdio.h>
#include <stdlib.h>
// *** Prototype Functions ***
void Post_Results (float*);
void Calculate (float*, float*, char*, float*);
void Get_Numbers (float*, char*, float*);

[Code]......

View 5 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 :: String Allocation To String Pointer

Feb 10, 2014

I am trying to read the string from user and the allocate it to the another string which is ptr string but not successful . Do I have to use any dynamic memory allocation here?

Code:
int main(){
char test[5];
char *strng, *base;
int i;
base=strng;
for(i=0; i<4; i++){

[Code]....

View 8 Replies View Related

C :: Tokenizing String Without Strtok / Other Functions

Jul 14, 2014

I am trying to make simpler equivalent of strtok().i want to separate string for my command line program. here is what i came up with

Code:

PVOID CmdArgs(PWCHAR Arg){
PWCHAR Return[10];
int I=0,s=0;
}

[code]....

i can not use winapi or standard c library because project im doing is pure ntdll api program (subsystem native in other words)

View 4 Replies View Related

C++ :: Parsing String To Recognize Trigonometric Functions

Sep 14, 2014

How do I create a function that can understand trigonometric functions?

Examples:

if I am to input: x^2 + sin(x)

The program will understand the the value between parenthesis preceded by a string "sin" will be computed as the sine of x. of any function in case.

I have the program here.

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;
enum types { DELIMITER = 1, VARIABLE, NUMBER }; //DEL = 1; VAR = 2; NUM = 3.
class analyzer {

[Code] .....

View 9 Replies View Related

Visual C++ :: String Passing Between Functions In SDI Application?

Apr 8, 2013

I am doing an project in SDI. I have two functions name sendtext(CString str) and displaytext(CString inr) both in different class. I have a pointer name pView to send the string str to function "displaytext". The problem is after some operations i get a text in str and i send that text to display text in the output screen i get the text and wen the second text comes to "displaytext" the former text disappears and the latest string only present. How can i display both the text in the output window on ClistCtrl class.

Code:
Void sendtext(CString str)
{
// do some operations
................
pView->displaytext(str);
}
void displaytext(CString inr) {
CListCtrl &ctlsde = this->GetListCtrl();
ctlsde.InsertColumn(1, _T("First "), LVCFMT_LEFT, 80);
int nItem;
nItem = ctlsde.InsertItem(0, inr);
}

View 14 Replies View Related

C :: Why Cannot Pass The Address Of String During Printf Or Scanf Functions

Jan 24, 2013

Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?

View 2 Replies View Related

C++ :: C Type Strings - Program To Ask User To Enter A String And Perform Functions

Oct 18, 2014

My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:

s – search
i – insert
a – append
d – delete
a – append
d – delete
r – replace
e – exit
s – search

This option will allow the user to search for a specified string in the worked-on string. If the string is

found, it will display the starting index (position) of the searched string in the worked-on string.

here is what i have so far.

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a_string[80];

[Code] .....

View 4 Replies View Related

C :: How To Return As A Pointer To A String

Aug 1, 2014

How to return as a pointer to a string?

View 5 Replies View Related

C :: Changing Value Of A String Through A Pointer

Jun 11, 2013

Basically, I have a pointer to a C string:

Code: char **objectData and a C string:

Code: char temp[350]; I need to assign the CONTENTS of the temp to the CONTENTS to which objectData points.

Code: *objectData = temp; //this changes the pointer. When temp is deleted, objectData points to some rubbish

**objectData = *temp; //this doesn't seem to be doing anything - the string to which objectData points does not change.

View 3 Replies View Related

C++ :: Binary Char Pointer Into String

Jun 12, 2013

Is there a more simple method to copy Buf into str? Buf is a binary string.

Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}

View 5 Replies View Related

C :: Assign Pointer Of A String To Integer

Mar 22, 2014

I have this code:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[code]....

What I want is basically to assign to the *p the pointer of the string so that i could do the following printf(" print string %s",*p); so i dont know how to do that.

View 6 Replies View Related

C :: Entering Characters Into A String Pointer

Feb 8, 2013

1. The debugger shows that the characters are entered into the word pointer, and when a punctuation or space character is encountered, I terminate the string with a ''. But when I use puts to print the string, garbage is printed. Why is this?

2. Also, if I don't allocate memory for word the compiler gives a warning about it being used uninitialised. But I didn't allocate memory for the array of pointers(words), and the compiler didn't give any warnings. Whats the difference between a pointer and an array of pointers?

Code:

// wordcount.c - count words.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

[Code]....

View 7 Replies View Related

C :: Assigning A Pointer To A String Literal

Sep 13, 2013

In another forum, this example code fragment was stated as being an example of undefined behavior. My understanding is that a literal string exists from program start to program termination, so I don't see the issue, even though the literal string is probably in a different part of memory.

Code: /* ... */
const char *pstr = "example";
/* or even */
char *pstr = "example";
/* as long as no attempt is made to modify the data pointed to by pstr, */
/* unless pstr is later changed to point to a stack or heap based string */

View 11 Replies View Related

C++ :: Converting Char Pointer To String

Mar 5, 2013

Here's the code I'm working on:

string* arrayPush(string *array, char **toks){

if(array[sizeofHistory -1].empty()){
//find the next available element
for(int i=0; i < sizeofHistory; i++ ){

[Code] ....

toks is an array of pointers to strings. I need to assign a toks to array[i].

View 10 Replies View Related

C/C++ :: Pointer-to-char To String Literal?

Oct 6, 2014

how string literal that works with the cin object?

char * str = "This is a string constant";

Is the str stored the address of the first character of the string literal?

But some books just state that the pointer-to-char (char pointer) stores the address of the string literal". So just wonder how it is.

When it is used with cout, cout just treats it like a string and instead of printing the address, it just prints out all characters one by one until it reaches the terminated null character.

If this is the case, then I am just wondering how cin works with it? with a statement like this cin >> str; ?

Does the computer allocate enough memory for it? and then cin stores the first character into the first address and then advances to the next address and stores the next character?

View 1 Replies View Related

C++ :: C-style String Array And Pointer

Feb 9, 2014

I was told that if I define

char *cstrp;
char cstra[c];

then the cstrp can be treated as cstra, and so I can also use

cin>>cstrp;

but when I write the following program, I find it don't work, don't have clue

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
char cstr[5];

[Code] ....

for cstr, it work exactly as what I expected, but for cstrp, no matter what I input, with a null terminator or not, I just got nothing printed. why? can we really use cstrp in that way or not? How to use it?

View 7 Replies View Related

C :: WAP To Remove Vowel String Using Pointer And Function

Jan 25, 2013

WAP to remove vowel string using Pointer and Function...

View 6 Replies View Related

C++ :: Unable To Compare A String With A Char Pointer

Jan 28, 2013

Ok, I'm having a few problems with strings, mostly string functions saying they're not able to compare a string with a char pointer.

int main()
{
int counter = 0;
int x, y, z;

[Code].....

My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).

View 2 Replies View Related

C++ :: Append Suffix To String With Pointer Arithmetic

Mar 1, 2013

Dynamic memory allocation and pointer arithmetic with char arrays.

The class was given to me in a very basic skeleton form with prototypes but no implementations, along with a test function to test my implementations. I CAN NOT use any C String functions in this assignment.

The part of the program which is troubling is the append function, which just appends a parameter string215 object to the end of the current string215 object.

// Add a suffix to the end of this string. Allocates and frees memory.
void string215::append(const string215 &suffix) {
char *output = new char[str_len(data)+suffix.length()+1];
for(int x = 0; x < str_len(data); x++) {
*output = *data;

[Code]...

This portion of the code is tested in the 13th test of the test function as shown here:

string215 str("testing");
...

// Test 13: test that append works in a simple case.
curr_test++;
string215 suffix("123");
str.append(suffix);
if (strcmp(str.c_str(), "testing123") != 0) {
cerr << "Test " << curr_test << " failed." << endl;
failed++;
}

Here is the description of the append class: Add the suffix to the end of this string. Allocates a new, larger, array; copies the old contents, followed by the suffix, to the new array; then frees the old array and updates the pointer to the new one.

My program aborts at the very end of the append function execution with the error message:

Debug Assertion Failed!

Program: [Source path]dbgdel.cpp
Line: 52

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
...

Abort || Retry || Ignore

Here's a pastebin of the .cpp and .h file for this program

string215.cpp: [URL] ....
string215.h: [URL] .....

View 14 Replies View Related







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